vendredi 27 janvier 2017

How to create proper relationships?

I have two types of users: Personal and Business. Personal user can belong to Business user. Thats what i created pivot table personal_users_business_user that have user_id,business_user_id.

I have User,PersonalUser and BusinessUser model. In User model i have this relationship:

  public function company()
    {
          return $this->belongsToMany('App\Models\PersonalUser','personal_users_business_users', 'user_id', 'business_user_id');
    }

Im using attach() method :

  $user->company()->attach($business_user_id);

It store data in pivot table. Now what i want in view is something like this:

  <input class="typeahead form-control" type="text" name="user_company"  @if($user->company->approved == 0) ? disabled : '' @endif value="">

But i dont how how to access to those fields from user in pivot table. Any suggestion?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire