Skip to content

Add #[Persistent] attribute for middleware #9218

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

ralphjsmit
Copy link
Contributor

@ralphjsmit ralphjsmit commented Mar 5, 2025

Hello, thank you very much for all the great work you did and are doing on Livewire!

Quite often it happens that you add a new middleware to your routes, but don't immediately realize that it also needs to be marked as persistent. In my opinion, it is not super-convenient to create the middleware and then look up a (big) service provider or something and then add the middleware in Livewire::addPersistentMiddleware().

This PR proposes a very easy solution to allow marking a middleware as #[Persistent] with a simple attribute, meaning that developers can just easily mark a middleware as persistent when creating them, without needing to open up a whole other file. It was actually pretty easy to do just inside the filterMiddlewareByPersistentMiddleware(), so I think this would be a great DX-improvement and would result in less middleware being "forgotten" to be marked as persistent.

I also added tests for the method. Thanks!

@joshhanley joshhanley changed the title feat: allow to add #[Persistent] attribute to middleware Add #[Persistent] attribute for middleware Mar 20, 2025
@maurocasas
Copy link

This actually is a pretty useful iteration!
Think of Multi-tenancy where you have a middleware which resolves tenant based upon subdomain.

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

Successfully merging this pull request may close these issues.

3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy