lundi 28 décembre 2015

Models, Resource Controllers and Middleware in Laravel 5.1

I have several resources in Laravel 5.1 that are represented by models. The models all have account_id and user_id. There is a pivot table of user_account that represents the relationship between accounts and users.

I have my routes in routes.php that are resource controllers such as route.asset.

I am looking to create one Middleware for all of these controllers such I can do before => ['belongstoaccount']

And in that middleware it should check:

User belongs to the account in account.asset (I currently use ->contains() in the controllers.)

The account_id of the asset matches the account->id.

I want to make one middleware for all these assets. Is this even possible? Should I be looking in $request for this information?

Thank you for any guidance,

Josh



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire