Hi there,
I'm returning to Laravel since my last stint with v4/v5. Wow so much has changed.
I have been using Node.js pretty extensively since, and in that ecosystem, a common pattern is to write middleware that can enrich the request with additional details.
In my case, I want to provide a "Organization Switcher" type of context. The current user can belong to many different organizations, and they have the option to select one from a dropdown.
At first I created a middleware to store this option, and found a thing called $request->attributes->get("KEY_NAME");
but it seems like retrieving these attributes might not be supported. I can't find documentation about them anywhere.
When I attempt to retrieve these request attributes in a Controller, it works great. But when I'm trying to use it in another middleware - specifically HandleIntertiaRequests
, I run into issues where the request attribute is missing. I tried playing with the priority of the middleware, but I'm not able to figure it out yet.
If it helps, my organization context middleware is a named middleware, whereas the handle inertia requests is a global.
Perhaps they both need to be global, but I'm a bit concerned I'm having difficultly finding documentation about enriching the request, perhaps there's a better solution?
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community