laravel protected $with code example
Example 1: laravel detach
// Detach a single role from the user...
$user->roles()->detach($roleId);
// Detach all roles from the user...
$user->roles()->detach();
Example 2: laravel eloquent associate
$account = App\Account::find(10);
$user->account()->associate($account);
$user->save();
Example 3: laravel scope
public function apply(Builder $builder, Model $model)
{
$builder->where('age', '>', 200);
}
Example 4: eloquent relationships
$roles = App\User::find(1)->roles()->orderBy('name')->get();