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

add support for BackedEnums to session #53235

Conversation

macbookandrew
Copy link
Contributor

@macbookandrew macbookandrew commented Oct 18, 2024

Similar to #52677, #52679, and #52792, using enums improves code readability, maintainability and reduces the hassle of using string values within the code itself.

This adds BackedEnum support to the session methods:

session()->put(RememberMeEnum::SESSION_KEY, true);
session()->forget(RememberMeEnum::SESSION_KEY, true);

This PR is backward compatible, with one minor(?) change to the flash() method: https://github.com/laravel/framework/pull/53235/files#r1806848088

This depends on #53234 being merged first.

* @param mixed $value
* @return void
*/
public function flash(string $key, $value = true)
public function flash($key, $value = true)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the one breaking change: removing the string type from the method.

I can revert this change and the doc if you like.

@taylorotwell
Copy link
Member

Thanks for your pull request to Laravel!

Unfortunately, I'm going to delay merging this code for now. To preserve our ability to adequately maintain the framework, we need to be very careful regarding the amount of code we include.

If applicable, please consider releasing your code as a package so that the community can still take advantage of your contributions!

@macbookandrew
Copy link
Contributor Author

@taylorotwell I wonder if you would reconsider this one. I removed the changes to the Arr::* helper from #53234 so this focuses only on the session store, and updated to use enum_value instead of checking the type as requested in #53234 (comment).

The use case/pain point here is multiple Livewire components that are reading and writing values using the same session key; it would be really nice to use an enum for the session key instead of a string.

No matter what you decide, thanks for taking a look!

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

Successfully merging this pull request may close these issues.

2 participants