1. Go to this page and download the library: Download bfg/route 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/ */
bfg / route example snippets
use Bfg\Route\Attributes\Get;
use Bfg\Route\Attributes\Resource;
class MyController
{
#[Get('my-route')]
public function myMethod()
{
}
}
#[Resource('my_resource')]
class MyResourceController
{
...
}
public function boot()
{
$this->configureRateLimiting();
$this->routes(function () {
Route::find(
// Path for search attributes,
// you can use class namespaces,
// directories and file paths
__DIR__ . '/../Http/Controllers',
// Here you can transfer the parent
// instance of the route from which
// the nesting will be created.
Route::middleware('web')
);
});
}
use Bfg\Route\Attributes\Get;
class MyController
{
#[Get('my-route')]
public function myMethod()
{
}
}
use Bfg\Route\Attributes\Get;
use Bfg\Route\Attributes\Middleware;
#[Middleware(MyMiddleware::class)]
class MyController
{
#[Get('my-route')]
public function firstMethod()
{
}
#[Get('my-other-route', middleware: MyOtherMiddleware::class)]
public function secondMethod()
{
}
}
use Bfg\Route\Attributes\Get;
use Bfg\Route\Attributes\Post;
use Bfg\Route\Attributes\Prefix;
#[Prefix('my-prefix')]
class MyController
{
#[Get('my-get-route')]
public function myGetMethod()
{
}
#[Post('my-post-route')]
public function myPostMethod()
{
}
}
use Bfg\Route\Attributes\Get;
use Bfg\Route\Attributes\Post;
use Bfg\Route\Attributes\Domain;
#[Domain('my-subdomain.localhost')]
class MyController
{
#[Get('my-get-route')]
public function myGetMethod()
{
}
#[Post('my-post-route')]
public function myPostMethod()
{
}
}