I have a complete application which is written using lumen. The application is complete. I just need to add order by clause with each query in the application which is somehow time taking to add. After searching everywhere I found the following method.
protected static function boot() {
parent::boot();
static::addGlobalScope('order', function (Builder $builder) {
$builder->orderBy('date', 'desc');
});
}
I shall have to add above function in each model. This is also a reasonable solution but I do not want to do this. I want to add this function on a single place rather than adding in each model like in any service provider or somewhere else.I am not much familure with this framework. Please, help if any one knows about its solution. Please, note that the timestamp field names for order by has different prefix. Eg. tbl_created_at is the Created_at field in a table named column and prnt_created_at field is Created_at field in a table named prints. Thanks for any help.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire