PHP code example of mojtabaahn / laravel-controller-routes

1. Go to this page and download the library: Download mojtabaahn/laravel-controller-routes 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/ */

    

mojtabaahn / laravel-controller-routes example snippets

 php

// routes/web.php

use MojtabaaHN\LaravelControllerRoutes\Routes;
use Illuminate\Support\Facades\Route;


Routes::make('UserController')->methods(function (ControllerAwareRouter $router) {
    $router->get('user/{user}', 'profile')->name('user.profile');
    $router->get('user/{user}/post/{post}','post')->name('user.post');
});

// Or

Routes::make()
    ->controller('UserController')
    ->methods(function (ControllerAwareRouter $router) {
        $router->get('user/{user}', 'profile')->name('user.profile');
        $router->get('user/{user}/post/{post}','post')->name('user.post');
    });

// Same as

Route::get('user/{user}', 'UserController@profile')->name('user.profile');
Route::get('user/{user}/post/{post}','UserController@posts')->name('user.posts');

// Using RouteRegistrar methods

Routes::make()
    ->prefix('user/{user}')
    ->name('user.')
    ->middleware('web')
    ->controller('UserController')
    ->methods(function (ControllerAwareRouter $router) {
        $router->get('/', 'profile')->name('profile');
        $router->get('posts','posts')->name('posts');
    });

// same as 

Route::prefix('user/{user}')
    ->name('user.')
    ->middleware('web')
    ->group(function(){
        Route::get('/', 'UserController@profile')->name('profile');
        Route::get('posts','UserController@posts')->name('posts');
    });