0
I wanted to know how to send the data of the query 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
How did you put the Return of your function in the controller? You just need to put the view/('view')->with([$var_para_chamar_no_blade -> $query]);
– Luiz Pillon
Got it, I’ll be trying
– Victor Gabriel
Luiz, look at the Review I edited in the publication
– Victor Gabriel
Luiz, I put, but this giving Object error
– Victor Gabriel
It is not necessary to use Audacoes here if you want to know more why, read: https://pt.meta.stackoverflow.com/q/846/28595
– user28595
Thank you! I’m new here
– Victor Gabriel
failed to assign the variable p to call in Blade, try like this: Return view('users.index')->with(['users' -> $query]);
– Luiz Pillon
he gives this error: Object of class Illuminate Database Eloquent Builder could not be converted to string
– Victor Gabriel
good.. think q missed the ->get() at the end. updates the return to: ->with(['users' -> $query->get()]);
– Luiz Pillon
is right: https://laravel.com/docs/5.5/queries#json-Where-clauses
– Luiz Pillon
Man, same mistake
– Victor Gabriel
face has some bo in query ai, exchange LIKE for like, if not scroll try to see here q is the same BO. https://answall.com/questions/165859/object-of-class-illuminate-database-eloquent-builder-could-not-be-converted-to-s
– Luiz Pillon