xxxxxxxxxx
$user->posts()->where('active', 1)->get();
xxxxxxxxxx
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class User extends Model
{
public function orders() {
return $this->hasMany(App\Order::class);
}
}
xxxxxxxxxx
N + 1
return new SongsCollection(Song::with('album')->get());
'songs' => SongResource::collection($this->whenLoaded($this->songs))
xxxxxxxxxx
$comment = Post::find(1)->comments()
->where('title', 'foo')
->first();
xxxxxxxxxx
$model->relation; // result of the relation, ie. null/model for x-1 relations or collection for x-m
$model->relation(); // relation object