我在laravel 5.8(Laravel框架)中有此代码,我想在控制器中使用@can我有此错误。
语法错误,意外的“更新书”(T_STRING)
如何在控制器中使用@can和@endcan我知道如何在刀片文件中使用
如何解决此错误?
这是我的控制器代码。
function search(Request $request)
{
if ($request->ajax()) {
$output = '';
$query = $request->get('query');
if ($query != '') {
$data = DB::table('books')
->where('title', 'like', '%' . $query . '%')
->orWhere('number', 'like', '%' . $query . '%')
->orWhere('pdf', 'like', '%' . $query . '%')
->orWhere('created_at', 'like', '%' . $query . '%')
->orderBy('id', 'desc')
->get();
} else {
$data = DB::table('books')
->orderBy('id', 'desc')
->get();
}
$total_row = $data->count();
if ($total_row > 0) {
foreach ($data as $book) {
$output .= '
<div class="col-md-3 ">
<div class="card">
<div class="card-body">
<div class="pdf-file">
<i class="fa fa-file-pdf"></i>
</div>
<h5 class="title">' . $book->title . '</h5>
<div class="date" style="display: flex; ">
<p><i class="fa fa-file-signature"></i> نمبرثبت ' . $book->number . '</p>
<p><i class="fa fa-calendar-alt"></i> ' . $book->created_at . ' </p>
</div>
<div class="download">
<a class="btn btn-dark btn-block" href=" /upload/files/' . $book->pdf . '"><i class="fa fa-download"></i></a>
</div>
<br>
<div style=" text-align: center;">
@can('update-book')
<div class="btn-group btn-group-xs">
<a href="/book/' . $book->id . '/edit" class="btn btn-sm btn-primary"><i class="fa fa-edit"></i></a>
</div>
@endcan
</div>
</div>
</div>
</div>
';
}
} else {
$output = '
<tr>
<td align="center" colspan="5">No Data Found</td>
</tr>
';
}
$data = array(
'table_data' => $output,
'total_data' => $total_row
);
echo json_encode($data);
}
}