Dinesh Uprety
@dineshuprety ·
Public
Secure controllers with attributes
PHPLaravel 13 API example based on official Laravel documentation. Source: https://laravel.com/docs/13.x/releases#expanded-php-attributes
PHP
CodeSnap // free canvas
Secure controllers with attributes
<?php
use Illuminate\Routing\Attributes\Controllers\Authorize;
use Illuminate\Routing\Attributes\Controllers\Middleware;
#[Middleware('auth')]
final class InvoiceController
{
#[Authorize('view', 'invoice')]
public function show(Invoice $invoice): Invoice
{
return $invoice;
}
}
// Further reading: https://laravel.com/docs/13.x/releases#expanded-php-attributes