jeudi 29 octobre 2015

Make a global when true in Laravel 5 Model

I come from cakePHP where it is possible to have every get or list query to include a standard where "something = something" in the Model. Per function in the controller this can be ignored, but for all others this is used.

Now I am wondering how to do this in Laravel 5. I would like to add something like below code in the Model or in the Controller (but preferably in the Model):

public function __construct(Page $page) {
    $page->where('is_active', 1);
}

So that when running any query on the pages table it will only give me active pages. Except when I manually add where('is_active', 0) or something else to include all active and inactive pages.

Any help would be very appreciated



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1SbG33d
via IFTTT

Aucun commentaire:

Enregistrer un commentaire