mercredi 14 novembre 2018

How to write a custom function in a model?

There is a model data:

class Order extends Model
{
}

How to write a custom method inside the Order class so that it can be called in constructor like this:

Order::myMethod()
Order->myMethod()

Where myMethod is:

public function myMethod() {
     return DB::query(<SQL QUERY>);
}

Purpose is to move SQL queries inside model's class, that don't mess this code in controllers.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2QIE9w2
via IFTTT

Aucun commentaire:

Enregistrer un commentaire