With Eloquent models adding scopes is easy:
public function scopeMyScope($query)
{
// Do stuff to that $query
}
But how to add scope to
Been using lukas's solution works like a treat; I am calling the scope from the model where it has been defined it just avoids duplicating the function.
$query = DB::table('page_views')
->where('id', $this->id)
->where('agent', 'NOT LIKE', '%bot%');
$query = (new myModel())->scopeMyScope($query);
$views = $query->count(DB::raw('distinct session, DATE(created_at)'));