Answers for "laravel relationship"

PHP
2

laravel wherehas

$users = User::whereHas('posts', function($q){
    $q->where('created_at', '>=', '2015-01-01 00:00:00');
})->get();
// only users that have posts from 2015 on forward are returned
Posted by: Guest on February-05-2021
3

laravel where has

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();
Posted by: Guest on May-07-2020
3

how to use where relationship laravel

Event::with(["owner", "participants" => function($q) use($someId){
    $q->where('participants.IdUser', '=', 1);
    //$q->where('some other field', $someId);
}])
Posted by: Guest on July-29-2020
0

laravel relationship

$comment = Post::find(1)->comments()
                    ->where('title', 'foo')
                    ->first();
Posted by: Guest on May-26-2021
0

laravel relationship

use App\Models\Post;

$comments = Post::find(1)->comments;

foreach ($comments as $comment) {
    //
}
Posted by: Guest on January-28-2021
0

laravel relationship

$model->relation; // result of the relation, ie. null/model for x-1 relations or collection for x-m
$model->relation(); // relation object
Posted by: Guest on July-13-2021

Code answers related to "laravel relationship"

Browse Popular Code Answers by Language