Я добавляю функцию поиска на мою страницу администратора и использую AJAX для поиска, но мне не удалось отобразить данные на моей странице. Выдает ошибку.
Я пытался добавить одинарную или двойную кавычку на каждой стороне, но это просто выдает мне ошибку каждый раз
это функция контроллера:
public function search(Request $request)
{
if($request->ajax())
{
$output = '';
$query = $request->get('query');
if($query != '')
{
$data =User::where('name', 'like', '%'.$query.'%')->get();
}
else
{
$data =User::orderBy('created_at' ,'desc')->get();
}
$total_row = $data->count();
if($total_row > 0)
{
foreach($data as $merchant)//That how i am showing data on the page
{
$output .=
"<tr>
<td>"{$users->name}"
"@if($users->allowded == 0)" //I need to add these if else functionality to my code but these thing are giving error
"@endif"
</td>
<td>{{$users->email}}</td>
<td>{{$users->permission->permission}}</td>
<td>
<a href="#" class="btn btn-xs btn-success">
<span style="padding-right: 16px;">Make Him Salaried User
</span>
</a>
<a href="#" class="btn btn-xs btn-success">
<span style="padding-right: 16px;">Make Him Commesioned User
</span>
</a>
<a href="#" class="btn btn-xs btn-success">
<span style="padding-right: 16px;">Make Him Salaried and Commesionded User
</span>
</a>
</td>
<td>
@if($users->user_status)
<a href="" class="btn btn-xs btn-danger">
<span style="padding-right: 10px;">Make Him Unpaid User
</span>
</a>
@else
<a href="" class="btn btn-xs btn-success">
<span style="padding-right: 16px;">Make Him Paid User
</span>
</a>
@endif
</td>
<td>
@foreach($cashtransfer as $cash)
@if($cash->user_id == $users->id)
{{ $cash->amount}}
@endif
@endforeach
</td>
<td>
@if($users->allowded)
<a href="" class="btn btn-xs btn-danger">
<span style="padding-right: 16px;">Bloack User</span>
</a>
@else
<a href="" class="btn btn-xs btn-success">
<span style="padding-right: 16px;">Allow User</span>
</a>
@endif
</td>
<td>
</td>
<td>
<a href="" class="btn btn-xs btn-danger">
<span style="padding-right: 16px;">Delete User</span>
</a>
</td>
</tr>";
}
}
else
{
//This is The Out Variable which is taking data to the page
$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);
}
}
Это ошибки, которые я получаю каждый раз:
// ->when($request->has('query'), function($q){
// $q->where('name','like','%'. request('query').'%');
// })->get();
$data =User::where('name', 'like', '%'.$query.'%')->get();
}
else
{
$data =User::orderBy('created_at' ,'desc')->get();
// $pagi = "<div> {$data->links()}</div>";
}
$total_row = $data->count();
if($total_row > 0)
{
foreach($data as $merchant)
{
$output .= "
<tr>
<td>"{$users->name}"
"@if($users->allowded == 0)"
"@endif"
</td>
<td>{{$users->email}}</td>
<td>{{$users->permission->permission}}</td>
<td><a href="#" class="btn btn-xs btn-success"> <span style="padding-right: 16px;">Make Him Salaried User</span></a><a href="#" class="btn btn-xs btn-success"> <span style="padding-right: 16px;">Make Him Commesioned User</span></a><a href="#" class="btn btn-xs btn-success"> <span style="padding-right: 16px;">Make Him Salaried and Commesionded User</span></a></td>
<td>
@if($users->user_status)
<a href="" class="btn btn-xs btn-danger"> <span style="padding-right: 10px;">Make Him Unpaid User</span></a>
@else
Почему я не могу просто опубликовать это?
Я получаю сообщения об ошибках, как будто мне нужно больше деталей