Illuminate\Database\Eloquent\Model::with PHP Method

with() public static method

Begin querying a model with eager loading.
public static with ( array | string $relations ) : Builder | static
$relations array | string
return Builder | static
    public static function with($relations)
    {
        if (is_string($relations)) {
            $relations = func_get_args();
        }
        $instance = new static();
        return $instance->newQuery()->with($relations);
    }

Usage Example

 public function getRoleByName($roleName)
 {
     $query = $this->model->with('roles')->whereHas('roles', function ($q) use($roleName) {
         $q->where('name', '=', $roleName);
     })->get();
     return $query;
 }
All Usage Examples Of Illuminate\Database\Eloquent\Model::with
Model