Skip to content

Commit f992f87

Browse files
committed
route names for CRUD routes
1 parent 5115623 commit f992f87

File tree

2 files changed

+39
-6
lines changed

2 files changed

+39
-6
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ All Notable changes to `Backpack CRUD` will be documented in this file
2020
- Nothing
2121

2222

23+
## [3.0.8] - 2016-08-05
24+
25+
### Added
26+
- automatic route names for all CRUD::resource() routes;
27+
2328
## [3.0.7] - 2016-08-05
2429

2530
### Added

src/CrudServiceProvider.php

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,39 @@ public function register()
8484
public static function resource($name, $controller, array $options = [])
8585
{
8686
// CRUD routes
87-
Route::post($name.'/search', $controller.'@search'); // TODO: make this work
88-
Route::get($name.'/reorder', $controller.'@reorder');
89-
Route::post($name.'/reorder', $controller.'@saveReorder');
90-
Route::get($name.'/{id}/details', $controller.'@showDetailsRow');
91-
Route::get($name.'/{id}/translate/{lang}', $controller.'@translateItem');
92-
Route::resource($name, $controller, $options);
87+
Route::post($name.'/search', [
88+
'as' => 'crud.'.$name.'.search',
89+
'uses' => $controller.'@search'
90+
]);
91+
Route::get($name.'/reorder', [
92+
'as' => 'crud.'.$name.'.reorder',
93+
'uses' => $controller.'@reorder'
94+
]);
95+
Route::post($name.'/reorder', [
96+
'as' => 'crud.'.$name.'.save.reorder',
97+
'uses' => $controller.'@saveReorder'
98+
]);
99+
Route::get($name.'/{id}/details', [
100+
'as' => 'crud.'.$name.'.showDetailsRow',
101+
'uses' => $controller.'@showDetailsRow'
102+
]);
103+
Route::get($name.'/{id}/translate/{lang}', [
104+
'as' => 'crud.'.$name.'.translateItem',
105+
'uses' => $controller.'@translateItem'
106+
]);
107+
108+
$options_with_default_route_names = array_merge([
109+
'names' => [
110+
'index' => 'crud.'.$name.'.index',
111+
'create' => 'crud.'.$name.'.create',
112+
'store' => 'crud.'.$name.'.store',
113+
'edit' => 'crud.'.$name.'.edit',
114+
'update' => 'crud.'.$name.'.update',
115+
'show' => 'crud.'.$name.'.show',
116+
'destroy' => 'crud.'.$name.'.destroy',
117+
]
118+
], $options);
119+
120+
Route::resource($name, $controller, $options_with_default_route_names);
93121
}
94122
}

0 commit comments

Comments
 (0)