lundi 19 novembre 2018

Post processing the returned object Laravel

I was wondering if there's a unified hooking mechanism in Laravel to modify the returned object after the controller has done its magic and return a View or Whatever other object it returned.

For example; I'm currently implementing an API which has a unified ResourceCollection with an extra field for meta information.

But, I'd like to populate that meta field after the Collection has been returned by the Controller.

For example:

class AccountController extends ApiController
{
    public function index()
    {
        return new ApiResourceCollection(Account::find(Auth::user()->getKey()));
    }
}

The ApiResourceCollection class returns a normal JSONResource as laravel implements it, just with some added logic attached to it.

However, I'd like to know if I can still modify or add information to the resource after the controller has run its magic.

Thanks in advance!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire