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.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire