0
I’m using leftJoin to bring data from 2 tables that are linked by a Belongstomany method to my index view.
Virtually all data of the two tables appear when I give a dd
in my variable, except the $id
of my user.
Running this code:
public function index(Request $request)
{
$setores = Setores::get();
$filiais_user = User::leftJoin('filiais_users','users.id','filiais_users.users_id')
->leftJoin('filiais','filiais.id','filiais_users.filiais_id')
->select('users.*','filiais.id');
dd($filiais_user);
That is what is returned:
In my User Model, I have the relationship this way:
public function filiais()
{
return $this->belongsToMany('App\Filial', 'projeto.filiais_users', 'filiais_id','id');
}
I have tried to specify in select so that it selects the column id
on the table users
, but it keeps returning without the values of this column. Can anyone indicate where is my error or any way that can solve?
Even with the
->get()
, theid
ta returning value Null– Habner
puts your entire model to take a look
– junio hyago
I figured it out, I took out the
join
and used only onewith
pulling the branch function I already had on the model, I appreciate your help. I will close the question– Habner