Uwe Keim
0
Q:

eloquent relationships

use Illuminate\Database\Eloquent\Builder;

// Retrieve posts with at least one comment containing words like foo%...
$posts = App\Post::whereHas('comments', function (Builder $query) {
    $query->where('content', 'like', 'foo%');
})->get();

// Retrieve posts with at least ten comments containing words like foo%...
$posts = App\Post::whereHas('comments', function (Builder $query) {
    $query->where('content', 'like', 'foo%');
}, '>=', 10)->get();
3
$account = App\Account::find(10);

$user->account()->associate($account);

$user->save();
2
$roles = App\User::find(1)->roles()->orderBy('name')->get();
0

New to Communities?

Join the community