PHP code example of nckrtl / route-maker

1. Go to this page and download the library: Download nckrtl/route-maker library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

nckrtl / route-maker example snippets


return [
    'method_defaults' => [
        'GET' => ['index', 'show'],
        'POST' => ['store'],
        'PUT' => ['update'],
        'DELETE' => ['destroy'],
        'PATCH' => ['edit'],
    ],
];

use NckRtl\RouteMaker\Facades\RouteMaker;

RouteMaker::routes();



namespace App\Http\Controllers;

class ContactController extends Controller
{
    public function show(): \Inertia\Response
    {
        return inertia('Contact');
    }
}

Route::get('/contact/{id}', [\App\Http\Controllers\ContactController::class, 'show'])->name('Controllers.ContactController.show');

use NckRtl\RouteMaker\Get;

...

#[Get(parameters: ['article:slug'])]
public function show(Article $article): \Inertia\Response
{
    return inertia('Article/Show', [
        'article' => $article->data->forDisplay(),
    ]);
}

use NckRtl\RouteMaker\{Get, Post, Put, Delete};

class ArticleController extends Controller
{
    #[Get]
    public function index(): \Inertia\Response
    {
        // GET /articles
    }

    #[Post(middleware: 'throttle:5,1')]
    public function store(Request $request): RedirectResponse
    {
        // POST /articles with rate limiting
    }

    #[Put(parameters: ['article:slug'])]
    public function update(Request $request, Article $article): RedirectResponse
    {
        // PUT /articles/{article:slug}
    }

    #[Delete(name: 'articles.remove')]
    public function destroy(Article $article): RedirectResponse
    {
        // DELETE /articles/{id} with custom route name
    }
}

class ArticleController extends Controller
{
    protected static string $routePrefix = 'articles';
    protected static string $routeMiddleware = 'auth:verified';

    ...
bash
php artisan vendor:publish --tag="route-maker-migrations"
php artisan migrate
bash
php artisan vendor:publish --tag="route-maker-config"