public function run()
 {
     foreach ([1, 2] as $account) {
         foreach (User::all() as $user) {
             $membership = new Membership();
             $membership->user_id = $user->id;
             $membership->account_id = $account;
             $membership->role_id = 1;
             $membership->is_owner = $user->id == 1 ? 1 : 0;
             $membership->save();
         }
     }
 }
 /**
  * @return bool|null
  * @throws \Exception
  */
 public function handle()
 {
     $account = $this->membership->account;
     $memberships = $account->memberships;
     //cannot revoke last membership or owner of the account
     if ($memberships->count() == 1) {
         return false;
     }
     if ($account->owner->id == $this->membership->member->id) {
         return false;
     }
     return $this->membership->delete();
 }
Beispiel #3
0
 /**
  * @return \Illuminate\Database\Eloquent\Model
  */
 public function handle()
 {
     $membership = new Membership();
     $membership->member()->associate($this->member);
     return $this->account->memberships()->save($membership);
 }