humans / laravel-singleton-routes
Add singleton routes for Laravel.
Installs: 7 464
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 1
Requires
- php: ^8.0
README
This is a package that adds support for Rails/Phoenix's singleton routes in Laravel. Singleton routes, or singular resources are routes that do not need to have an identifier as a context.
Unlike standard resources, singleton routes do not have an index method.
An example for this would be updating the current user's details.
show GET /my/profile
create GET /my/profile/create
store POST /my/profile
edit GET /my/profile/edit
update PUT|PATCH /my/profile
destroy DELETE /my/profile
Installation and Usage
Install the package with composer
composer require humans/laravel-singleton-routes
Register a singleton route.
Route::singleton('profile', PasswordController::class);
Register a nested singleton route.
Route::singleton('accounts.suspension', AccountSuspensionController::class) ->only('show', 'store', 'destroy');
Like other Laravel resources, you will have access to resource methods such as middleware
, only
, except
. As of the moment, it's not possible to chain it after calling a Route method. Route::prefix()->singleton()
WILL NOT work.
Wrapping the registration in a group will make it work.
Route::prefix('admin')->as('admin.')->group(function () { Route::singleton('theme', ThemeController::class)->only('update'); // url => PUT|PATCH /admin/theme // name => admin.theme.update });