laravel-actions
laravel-actions copied to clipboard
Ability to define resourceful Action routes
I absolutely love this package, but the only thing I don't like is having to declare all of my Action routes individually, and losing the ability to define resourceful routes.
This PR attempts to achieve this, by leveraging the Route::resource()
function and swaping out the Controller@action
for the action class.
Example usage:
// By default, it will look for all actions in the App\Actions namespace
Route::actions('addresses');
// If we only want to to generate index/show routes
Route::actions('addresses')->only('index', 'show');
// If our action is not in the default namespace, we can specify the namespace
Route::actions('addresses', 'App\Actions\Addresses');
// Because we are leveraging the Route::resource() method, all other helpers are readily
// available for us to chain on to
Route::actions('addresses')->only('index')->middleware('signed');
The benefit of this is that it will force developers to have consistent routing AND consistent Action naming. Now the names of these are up for grabs, but I've gone for:
-
GetAddresses
- this replacesController@index
-
ShowCreateAddress
- this replacesController@create
-
ShowAddress
- this replacesController@show
-
ShowEditAddress
- this replacesController@edit
-
CreateAddress
- this replacesController@store
-
UpdateAddress
- this replacesController@update
-
DeleteAddress
- this replacesController@destroy
Example - the following two route declarations:
Route::actions('addresses');
Route::actions('order-items');
produces the following routes:
As I mentioned above, if the Action is under a different namespace, we can specify that:
Route::actions('orders', 'App\Actions\Order')->only(['show', 'store']);
which produces: