php - Link Tables in Laravel 5 -
i writing application requires 2 tables linked using link table, there 3 tables in total.
//------- users //------ id, name, email, password //---- useraccounttype //---- id, name, description //--- useraccountlink //--- id, user_id, type_id,
the user able have multiple account types (admin, normal, developer)... also, have set foreign keys restraints.
the problem don't understand how link these, , have tried following:
class user extends model { // implementation public function account_type() { $this->hasmany('useraccounttypelink', 'id', 'id'); } } class useraccounttype extends model { // implementation } class useraccounttypelink extends model { // implementation public function user_account() { return $this->hasone('useraccounttype', 'type_id', 'id'); } }
my expected output that, example, user 1 has account of "admin" , "developer" returned. @ moment, can't seem desired output. ideas going wrong?
you don't need model intermediate useraccounttypelink table. have here more info on how create many-to-many relation in eloquent: http://laravel.com/docs/5.1/eloquent-relationships#many-to-many
Comments
Post a Comment