Skip to content

Conversation

@jrd-lewis
Copy link
Contributor

@jrd-lewis jrd-lewis commented Jul 26, 2025

Add a softDeletableResources method for the Router class to register multiple resource controllers that all use the withTrashed method.

Example

Route::softDeletableResources([
    'permissions' => PermissionController::class,
    'roles' => RoleController::class,
]);

Output:

Same as Route::resources(), but includes soft deleted models in the query for show, update, destroy and edit

GET|HEAD        permissions ................................... permissions.index › PermissionController@index
POST            permissions ................................... permissions.store › PermissionController@store
GET|HEAD        permissions/create .......................... permissions.create › PermissionController@create
GET|HEAD        permissions/{permission} ........................ permissions.show › PermissionController@show
PUT|PATCH       permissions/{permission} .................... permissions.update › PermissionController@update
DELETE          permissions/{permission} .................. permissions.destroy › PermissionController@destroy
GET|HEAD        permissions/{permission}/edit ................... permissions.edit › PermissionController@edit
GET|HEAD        roles ..................................................... roles.index › RoleController@index
POST            roles ..................................................... roles.store › RoleController@store
GET|HEAD        roles/create ............................................ roles.create › RoleController@create
GET|HEAD        roles/{role} ................................................ roles.show › RoleController@show
PUT|PATCH       roles/{role} ............................................ roles.update › RoleController@update
DELETE          roles/{role} .......................................... roles.destroy › RoleController@destroy
GET|HEAD        roles/{role}/edit ........................................... roles.edit › RoleController@edit

Benefit:

It would save from having to manually do the following for each resource controller where it uses the withTrashed scope:

Route::resource('permissions', PermissionController::class)->withTrashed();
Route::resource('roles', RoleController::class)->withTrashed();

Edited to reflect the updated method name.

@taylorotwell taylorotwell merged commit 2a62e88 into laravel:12.x Jul 27, 2025
60 checks passed
@browner12
Copy link
Contributor

This seems like such an odd way to group things. You've now created a behavior connection between these 2 resources that exists purely by happenstance, not by intent.

@jrd-lewis jrd-lewis deleted the feature/softDeleteResources branch July 28, 2025 22:34
@denjaland
Copy link
Contributor

I realize I'm late to the party, but the naming seems very odd to me to be honest. "SoftDeletable" for me means the "can be soft deleted", not that they are included.

I don't think I like this change...

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.

4 participants