Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Middleware prority #24

Closed
iainheng opened this issue Nov 18, 2017 · 2 comments
Closed

Middleware prority #24

iainheng opened this issue Nov 18, 2017 · 2 comments

Comments

@iainheng
Copy link

I have a middleware only apply to a controller but I want my middleware to execute before pjax's middleware.

Example code of my middleware:

public function handle($request, Closure $next)
{
        $booking = session()->get('booking');

        if (!$booking) {
            $request->session()->flash('alert-warning', 'Your session is expired.');

            $request->headers->remove('X-PJAX');

            return redirect()->route('booking.index');
        }

        return $next($request);
}

The purpose of my middleware is to disable PJAX and redirect with normal request if my session variable is empty.

Do you have any idea to achieve this?

@freekmurze
Copy link
Member

I'm not sure, but I suspect the order of registering the middleware in the Kernel is respected.

@iainheng
Copy link
Author

iainheng commented Nov 19, 2017

Thanks. I was looking at the $middlewarePriority property in Kernel but I don't feel like overriding it. So I end up created another $middlewareGroups just for PJAX enabled routes

'pjax' => [
            ValidateBookingSession::class,
            \Spatie\Pjax\Middleware\FilterIfPjax::class
        ],

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants