Reputation: 460
I have a table content
. So when I retrive anything from that table using laravel eloquent, I need to set a global where clause Content::where('is_playlist', 1)->get();
, so that every time I retrieve data from that table, I should automatically filtered with that particular where clause.
Upvotes: 1
Views: 235
Reputation: 7334
You can create a scope function in the model to filter that out e.g:
public function scopePlaylist($query)
{
return $query->where('is_playlist', 1);
}
This means you can easily call, Content::playlist()->get()
and you'll have only playlist content.
I hope this is useful?
Upvotes: 1