samedi 13 juillet 2019

Laravel adding a global condition on an eloquent

I get the invoices in multiple pages using a single query.

Query Code:

$invoices = ImportInvoice::withSupplier() -> withCreatedByAndUpdatedBy() -> orderedName() -> paginate(10);

PROBLEM:

I have added approve field in database which is boolean value weather the invoice is approve (1) or not approve (0).

So now I have to add where('approve', 1) to get the approved invoices.

Problem is that I will edit this eloquent in multiple controllers.

Question is:

Is there a way to add this where condition in the model? Plus sometimes I want to return the Not Approved invoices.

It is similar to Soft Delete created by Laravel.

Soft delete does not get returned when calling a query but if I want to call it I just call withTrashed() function.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire