0

My route:

Route::get('deleterequest/{request_id}', 'RequestController@getDeleteRequest')->name('getDeleteRequest');

In view, i want to click a tag to call this route View:

<a onclick=" confirmDelete({{ $request->task_id }})" href="#"  ><span class="fa fa-trash-o"></span></a>
<script type="text/javascript">


function confirmDelete(id){
    document.location.href="{!! route('getDeleteRequest', $id); !!}";
}

when i run the code, it show error message:

Undefined variable: id

2 Answers 2

4

I just you need to parse it and replace..

function confirmDelete(id){
    let url = "{{ route('getDeleteRequest', ':id') }}";
    url = url.replace(':id', id);
    document.location.href=url;
}

or just

<a onclick="confirmDelete({{route('getDeleteRequest', $request->task_id) }})" href="#"  ><span class="fa fa-trash-o"></span></a>

function confirmDelete(url){
    document.location.href=url;
}
Sign up to request clarification or add additional context in comments.

Comments

0

goto your_project_folder\config and create file constants.php if it's not exist and then define site_path constant inside it

define('SITE_PATH', 'http://www.yoursite.org/');
  • and then use like this

window.location = SITE_PATH+'deleterequest/'+id;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.