eloquent - Laravel QueryBuilder - hook before a query is executed -
i alter queries before execution, example
event::listen('which event?', function($query) { $query->where('foo', 'bar'); });
so example::where('name', 'baz')->get()
produce sql code:
select * example name = 'baz' , foo = 'bar'
.
is possible?
this best handled global scope on model.
sometimes may wish define scope applies queries performed on model. in essence, how eloquent's own "soft delete" feature works. global scopes defined using combination of php traits , implementation of illuminate\database\eloquent\scopeinterface.
Comments
Post a Comment