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

[11.x] Allow BackedEnum to be passed to Route::can() #52792

Merged
merged 2 commits into from
Sep 16, 2024

Conversation

Omegadela
Copy link
Contributor

Hi,

Like the recently merged #52677 and #52679 using enums improves code readability, maintainability and reduces the hassle of using string values within the code itself.

This PR proposes to add BackedEnum support to the can method on \Illuminate\Routing\Route, allowing to use it inline for simple routing.

Route::post('/request', function () {...})->can(Permissions::CAN_REQUEST);

This PR is backward compatible and shouldn't bring any breaking changes.

@Omegadela
Copy link
Contributor Author

$ ./vendor/bin/phpunit --filter RouteCanBackedEnum
PHPUnit 11.3.5 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.2.23
Configuration: /srv/ro/www/phpunit.xml.dist

..                                                                  2 / 2 (100%)

Time: 00:01.196, Memory: 156.50 MB

OK (2 tests, 7 assertions)

@Omegadela Omegadela force-pushed the route-can-backed-enums branch from cdb5098 to facb6e6 Compare September 14, 2024 15:18
@Omegadela Omegadela force-pushed the route-can-backed-enums branch from facb6e6 to 594c45a Compare September 14, 2024 15:23
@crynobone crynobone changed the title Allow backed enums to be passed to Route::can() [11.x] Allow BackedEnum to be passed to Route::can() Sep 16, 2024
@taylorotwell taylorotwell merged commit 56d6194 into laravel:11.x Sep 16, 2024
31 checks passed
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