0
Hello, I’m making Join between two table to display the user name in the view, but this giving the following error:
Call to a member function select() on string
My controller:
$postagens = Postagens::all()->sortByDesc('created_at')
->join('users','users.id' , '=', 'postagens.usuario' )
->select('users.name as nomeusuario')
->get();
return view('index',compact('postagens'));
The view:
@foreach ($postagens as $pubs)
@postagens()
@slot('titulo')
{{$pubs['nomePost']}}
@endslot
@slot('descricao')
{{$pubs['descricao']}}
@endslot
@slot('dia')
{{$pubs['created_at']}}
@endslot
@slot('id')
{{$pubs['nomeusuario']}}
@endslot
@endpostagens
@endforeach
gave it now: Join() expects at Most 2 Parameters, 4 Given
– spider tek
I have now given: Call to Undefined method Illuminate Database Eloquent Builder::sortByDesc()
– spider tek
@joaogabriel97, I didn’t even notice the error of the function you wrote. It’s not
sortByDesc
but yesorderBy
where this is defined which field and type of the order. Look at documentation: https://laravel.com/docs/5.8/queries#Ordering-grouping-limit-and-offset– Victor Carnaval
@joaogabriel97, solved your problem?
– Victor Carnaval