PHP code example of diyorbek / laravel-attribute-routes

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

    

diyorbek / laravel-attribute-routes example snippets


'providers' => [
    ...
    Diyorbek\AttributeRoutes\AttributeRouteServiceProvider::class,
],



namespace App\Http\Controllers;

use Diyorbek\AttributeRoutes\Routing\Attributes\Get;
use Diyorbek\AttributeRoutes\Routing\Attributes\Post;

class PostController extends Controller
{
    #[Get('/posts', name: 'posts.index', middleware: ['web'])]
    public function index()
    {
        return view('posts.index');
    }

    #[Post('/posts', name: 'posts.store', middleware: ['web'])]
    public function store()
    {
        // Сохранение данных
    }
}

#[Get('/url', name: 'route.name', middleware: ['web', 'auth'])]

(new \Diyorbek\AttributeRoutes\AttributeRouteRegistrar())->registerRoutes(app_path('Custom/Controllers'));