hasOneThrough in php code example
Example 1: laravel has one through
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Mechanic extends Model
{
/**
* Get the car's owner.
*/
public function carOwner()
{
return $this->hasOneThrough('App\Owner', 'App\Car');
}
}
Example 2: eloquent relationships
$roles = App\User::find(1)->roles()->orderBy('name')->get();