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

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

node.js - How to abort query on demand using Neo4j drivers -