how to make button in table to route to url

  html-table, jquery, laravel, php

I have table <thead> initialized in in blade and foreach loop for <tbody> in controller

so this is how it looks in controller:

foreach($data as $row)
        $output .= '


            <a href={{url(/edit/'.$row->id.')}} class="...">Edit</a>
            <a href="#" class="...">Delete</a>


and in the blade, initialized like this:


         <th> BUTTON </th>




and the script to fetch data into the <tbody>:



 function fetch_customer_data(query = '')
   url:"{{ route('live_search.action') }}", // live_search: is the blade where the table is
    $('tbody').html(data.table_data); // TABLE DATA

 $(document).on('keyup', '#search', function(){
  var query = $(this).val();

the data and the button appear in the table but the button does not work properly. there is a problem with how I’m using the button in the table, this button: <a href= "{{url(/edit/'.$row->student_id.')}}" class="...">Edit</a> generates this url: http://sms.test/%7B%7Burl(/edit/2)%7D%7D while the url should look like this: http://sms.test/edit/ID22 but when i change the href= "{{url(/edit/'.$row->student_id.')}}" to href= "#" it displays the # in the url bar. so i guess the problem is in this line "{{url(/edit/'.$row->student_id.')}}"

this is the route to edit:
Route::get('/edit/{id}', '[email protected]');

and the function edit @controller looks like this:

public function edit($id)
      $student = Student::find($id); 
      $students = Student::all();
      return view('student',['students'=>$students,'student'=>$student,'layout'=>'edit']);


I tried every method I know but could not get it to work:( please help

Source: Laravel

Leave a Reply