Laravel 4: How to add scope to DB::table?
With Eloquent models adding scopes is easy: public function scopeMyScope($query) { // Do stuff to that $query } But how to add scope to DB::table ? I use this query to get page views: $views = DB::table('page_views') ->where('id', $this->id) ->where('agent', 'NOT LIKE', '%bot%') ->count(DB::raw('distinct session, DATE(created_at)')); I also show the most popular pages etc with other queries, but with the same where conditions. So I would like to only define my where conditions once and reuse them in all other page view DB::table queries. DB::table doesn't have support for scopes. What you