PHP code example of g4t / easyroute

1. Go to this page and download the library: Download g4t/easyroute 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/ */

    

g4t / easyroute example snippets




namespace App\Http\Controllers;

use G4T\EaseRoute\Attributes\Route;
use G4T\EaseRoute\Attributes\Get;
use G4T\EaseRoute\Attributes\Post;

#[Route(uri: 'users', middleware: ['auth'])]
class UserController extends Controller
{
    #[Get]
    public function index()
    {
        return "List of users";
    }

    #[Get(onController: true)]
    public function show($id)
    {
        return "User: $id";
    }

    #[Post('create')]
    public function store()
    {
        return "Create user";
    }
}

'cache' => true

php artisan route:cache

return [
    'controllers_path' => [app_path('Http/Controllers')],
    'cache' => true,
];

GET      users                          UserController@index
GET      user/show/{id}                 UserController@show
POST     users/create                    UserController@store

app/
├─ Http/
│  ├─ Controllers/
│  │  ├─ UserController.php
│  │  └─ Admin/
│  │     └─ AdminController.php
bootstrap/
└─ cache/
   └─ routes-v7.php
config/
└─ route-attribute.php
bash
php artisan vendor:publish --provider "G4T\EaseRoute\EaseRouteServiceProvider"