I'm trying to have Auth::user()->building to return the building ID it is attached to. Right now it's returning Null. What am I doing wrong? Should I explicitly declare something somewhere? Thank you.
My tables :
users (id, name, etc.)
buildings (id, name)
building_user (building_id, user_id) has values ( 7 = building_id, 1 = user_id) with primary key on the two of them combined.
App\User
...
public function building(){
return $this->belongsTo('App\Building');
}
...
and
App\Building
...
public function users()
{
return $this->hasMany('App\User');
}
...
** EDIT **
I tried doing $building->users on view, and received the error
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'users.building_id' in 'where clause' (SQL: select * from `users` where `users`.`building_id` = 7 and `users`.`building_id` is not null)
Seems it's trying to not do a relational search. And searching the user table for a building_id column.