Laravel 5 custom query builder functions


I finally found an easy solution for this.

Just create a service provider and in the boot function do the following:

$queryBuilder = app(\Illuminate\Database\Query\Builder::class);

$queryBuilder::macro('filter', function (\Illuminate\Http\Request $request) {});

In the example you’ll be able to attach a request object as a parameter of the query, so you can finally do…


Hope this helps!