I would like to know how to send the query data in json through the controller and how the view should receive them.
Controller:
$dados = $req->all();
$query = "";
if($dados['filter'] == 1)
{
$query = User::where('id','LIKE','%'.$dados['search'].'%');
}
else if($dados['filter'] == 2)
{
$query = User::where('name','LIKE','%'.$dados['search'].'%');
}
else if($dados['filter'] == 3)
{
$query = User::where('email','LIKE','%'.$dados['search'].'%');
}
return view('users.index')->with([$users->$query]);
View:
@foreach($users as $user)
<tr>
<td>{{$user->id}}</td>
<td>{{$user->name}}</td>
<td>{{$user->email}}</td>
</tr>
@endforeach