After escaping the single quote, I included a URL link inside the Controller and passed it through json_encode
. However, when I clicked on the URL link, it did not work and showed this:
https://i.sstatic.net/3GIq1.png
The URL appeared like this:
http://localhost/BSProject/public/%7B%7B%20URL::to('schedule/24/edit')
Below is the Controller link:
public function liveSearch(Request $request)
{
if($request->ajax())
{
$output = '';
$query = $request->get('query');
if($query != '')
{
$data = DB::table('schedules')
->where('schedule_number', 'like', '%'.$query.'%')
->orWhere('route_name', 'like', '%'.$query.'%')
->orWhere('user_first', 'like', '%'.$query.'%')
->orWhere('id', 'like', '%'.$query.'%')
->get();
}
else
{
$data = DB::table('schedules')
->get();
}
$total_row = $data->count();
if($total_row > 0)
{
foreach($data as $row)
{
$output .= '
<tr>
<td>'.$row->id.'</td>
<td>'.$row->schedule_number.'</td>
<td>'.$row->route_name.'</td>
<td>'.$row->user_first.'</td>
<td>'.$row->created_at.'</td>
<td> <a style="margin-left: 5em; " href="{{ URL::to(\'schedule/' .$row->id .'/edit\')">
<button style=" font-size: 1em; width: 4.5em; height: 2.5em;" type="button" class="btn btn-success btn-sm">Edit
</button>
</a>
</tr>
';
}
}
else
{
$output = '
<p>
No Schedule Lists found
</p>
';
}
echo json_encode($output);
}
}
View
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>ID</th>
<th>Schedule_number</th>
<th>Route</th>
<th>User</th>
<th>Created_at</th>
<th>edit</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
Javascript
fetch_customer_data();
function fetch_customer_data(query = '')
{
$.ajax({
url:"{{ route('user.schedule.liveSearch') }}",
method:'GET',
data:{query:query},
dataType:'json',
success:function(output)
{
console.log(output);
$('tbody').html(output);
}
})
}
$(document).on('keyup', '#search', function(){
var query = $(this).val();
fetch_customer_data(query);
});
Here is the edit link URL that was mentioned earlier: https://i.sstatic.net/DRK0T.png