php - Laravel get model by hasManyThrough -
i have 3 classes - user, business , businessroleuser (and respective tables)
(user) id | first_name | last_name
(business) business_id | business_name
(business_role_user) user_id | business_id | role_id
i have combined role of user in same table multiple roles user's can have towards business i.e. admin, staff, etc. in business_roles table.
i access business model through logged in user update fields i.e.
$business = user::find(auth::id())->business(); $business->fill(input::all()); $business->save();
at present in user class have following (really each user associated 1 business):
public function business() { return $this->hasmanythrough('app\business', 'app\businessroleuser', 'business_id', 'user_id'); }
but if simple dd(user::find(auth::id())->business->business_name);
it throws error
business name undefined
it's not finding business model associated user. i've looked @ many examples of hasmanythrough failing work, appreciate help!
(note user table uses id other tables use user_id, not sure if causing issue)
Comments
Post a Comment