association in laravel code example
Example 1: eloquent relationships
$roles = App\User::find(1)->roles()->orderBy('name')->get();
Example 2: laravel poly morphic relationship
class Mechanic extends Model
{
/**
* Get the car's owner.
*/
public function carOwner()
{
return $this->hasOneThrough(
'App\Owner',
'App\Car',
'mechanic_id', // Foreign key on cars table...
'car_id', // Foreign key on owners table...
'id', // Local key on mechanics table...
'id' // Local key on cars table...
);
}
}