Created
May 22, 2018 16:09
-
-
Save jsdecena/f3fc6441717e2ef915913edd32e252be to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
users | |
- id | |
- type (string) | |
user_user | |
- user_id_1 | |
- user_id_2 | |
User extends Model { | |
.... | |
public function agents() | |
{ | |
return $this->belongsToMany( | |
User::class, | |
'user_user', | |
'user_id_1', | |
'user_id_2') | |
->where('type', '=', 'agent'); | |
} | |
// and so on | |
.... | |
} | |
// Then I can save it with | |
$agent = factory(User::class)->create(['type' => 'agent']); | |
User::agents()->save($agent); | |
// And output it with | |
return User::agents(); // Collection of users with agent type |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment