Skip to content

Routing Attributes Reference ​

PHP 8.1+ attributes for declaring routes on controllers.

Route ​

Base route prefix for a controller:

php
use Nexphant\Route;

#[Route('/api/users')]
class UserController { }

Get ​

php
use Nexphant\Get;

#[Get('/')]
public function index(): array { }

#[Get('/{id}')]
public function show(int $id): array { }

Post ​

php
use Nexphant\Post;

#[Post('/')]
public function store(Request $request): array { }

Put ​

php
use Nexphant\Put;

#[Put('/{id}')]
public function replace(Request $request, int $id): array { }

Patch ​

php
use Nexphant\Patch;

#[Patch('/{id}')]
public function update(Request $request, int $id): array { }

Delete ​

php
use Nexphant\Delete;

#[Delete('/{id}')]
public function destroy(int $id): array { }

Combined Example ​

php
#[Route('/api/users')]
class UserController
{
    #[Get('/')]
    public function index(): array { return DB::table('users')->get(); }

    #[Post('/')]
    public function store(Request $req): array { /* ... */ }

    #[Patch('/{id}')]
    public function update(Request $req, int $id): array { /* ... */ }

    #[Delete('/{id}')]
    public function destroy(int $id): array { return ['deleted' => true]; }
}

Released under the MIT License.