what laravel rleonship fits this databa´structure code example
Example 1: whereHas site:https://laravel.com/docs/
use Illuminate\Database\Eloquent\Builder;
$posts = Post::whereHas('comments', function (Builder $query) {
$query->where('content', 'like', 'code%');
})->get();
$posts = Post::whereHas('comments', function (Builder $query) {
$query->where('content', 'like', 'code%');
}, '>=', 10)->get();
Example 2: by default null eloquent user data in relationship in laravel 8
{{ $post->author->name or 'No author' }}
public function author()
{
return $this->belongsTo('App\Author')->withDefault();
}
public function author()
{
return $this->belongsTo('App\Author')->withDefault([
'name' => 'Guest Author',
]);
}