Skip to content

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
30 checks passed
@Omegadela Omegadela deleted the route-can-backed-enums branch December 30, 2024 13:44
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