PHP code example of ahmednour / laravel-attribute-routing
1. Go to this page and download the library: Download ahmednour/laravel-attribute-routing 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/ */
ahmednour / laravel-attribute-routing example snippets
#[Prefix('api/leads')]
#[Middleware(['api', 'auth:sanctum'])]
#[Name('leads.')]
class LeadController
{
#[Get('', name: 'index')]
#[WithPermission(PermissionEnum::VIEW_LEADS)]
public function index(LeadListQuery $query): AnonymousResourceCollection { /* ... */ }
#[Post('', name: 'store')]
#[WithPermission(PermissionEnum::CREATE_LEAD)]
#[Throttle(6)]
public function store(LeadRequest $request): JsonResponse { /* ... */ }
#[Delete('{lead}', name: 'destroy', where: ['lead' => '[0-9]+'])]
#[WithPermission(PermissionEnum::DELETE_LEAD)]
public function destroy(Lead $lead): JsonResponse { /* ... */ }
}
use AhmedNour\AttributeRouting\Attributes\{Get, Post, Prefix, Middleware, Name};
#[Get(
path: 'reports/{report}',
middleware: ['signed'], // string or array
prefix: 'admin', // extra prefix for this route only
name: 'reports.show',
where: ['report' => '[0-9]+'],
withoutMiddleware: ['auth:sanctum'],
)]
#[Get('export', name: 'leads.export')]
#[Get('download')]
public function export(): StreamedResponse { /* ... */ }
#[Prefix('api/auth')]
#[Middleware(['api', 'auth:sanctum'])]
class LoginController
{
// The one route in this controller that must stay public.
#[Post('login', name: 'auth.login')]
#[WithoutMiddleware('auth:sanctum')]
#[Throttle(5)]
public function login(LoginRequest $request): JsonResponse { /* ... */ }
}