Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

humans/laravel-singleton-routes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Laravel Singleton Routes

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
});

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages