How to extend the method get()
in eloquent class, to add some code that does a join whenever it is called.
Whenever a method all()
, find or get()
is called, add that join:
static::join('clientes', 'clientes.id', '=', 'faturas.cliente_id');
Thanks
Have you tried eager loading? You can also set protected $with = array('clients');
in your Model.
You could also overload the newQuery
Method by extending the Model class.
class BaseModel extends Model {
public function newQuery($excludeDeleted = true)
{
$builder = parent::newQuery($excludeDeleted);
$builder->join('clientes', 'clientes.id', '=', 'faturas.cliente_id');
return $builder;
}
}