Fresh code drop

Secure controllers with attributes

PHP

Laravel 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

Turn your code into a post.Five templates are free—no account needed.

Remix this snap