Last active
August 29, 2015 14:16
-
-
Save foysalit/7ad38a30687e04cc89be to your computer and use it in GitHub Desktop.
query eloquent relation
This file contains 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
public function users() | |
{ | |
return $this->hasMany('App\User'); | |
} | |
public function tasks() | |
{ | |
return $this->hasMany('App\Task'); | |
} |
This file contains 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
$comps = App\User::('tasks')->first(); | |
dd($comps->tasks); |
This file contains 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
public function company() | |
{ | |
return $this->belongsTo('App\Company'); | |
} |
This file contains 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
public function company() | |
{ | |
return $this->belongsTo('App\Company'); | |
} | |
public function tasks() | |
{ | |
return $this->belongsTo('App\User', 'company_id'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment