PHPackages                             devvelvet/laraattr - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. devvelvet/laraattr

ActiveLibrary[HTTP &amp; Networking](/categories/http)

devvelvet/laraattr
==================

Build Laravel APIs by adding PHP 8 attributes to your models.

v0.2.0(3mo ago)02MITPHPPHP ^8.1

Since Apr 10Pushed 3mo agoCompare

[ Source](https://github.com/devvelvet/laraattr)[ Packagist](https://packagist.org/packages/devvelvet/laraattr)[ RSS](/packages/devvelvet-laraattr/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (2)Dependencies (8)Versions (3)Used By (0)

LaraAttr
========

[](#laraattr)

> Build Laravel APIs by adding PHP 8 attributes to your models.

LaraAttr replaces the boilerplate Laravel API development requires (controllers, form requests, resources, route registration, …) with PHP 8 attribute declarations on your models. Inspired by Java Spring Boot's annotation-driven design, but built around Laravel's "elegance" and "developer happiness" philosophy.

```
#[ApiResource(prefix: '/api/users', name: 'users', resource: UserResource::class)]
#[Middleware('auth:sanctum', only: ['store', 'update', 'destroy'])]
#[Middleware('throttle:60,1')]
#[Schema(UserSchema::class)]
#[With(['profile'])]
#[Searchable(['name', 'email'])]
#[Sortable(['created_at', 'name'])]
#[Paginate(perPage: 20)]
#[Cache(ttl: 60)]
class User extends Model {}
```

That single block above auto-generates all of the following:

- `GET /api/users` (search + sort + pagination + response caching + profile eager-loaded)
- `GET /api/users/{id}` (profile eager-loaded)
- `POST /api/users` (with auto validation)
- `PUT/PATCH /api/users/{id}` (with auto validation + `unique` self-exclusion via `{id}`)
- `DELETE /api/users/{id}`
- `auth:sanctum` on write endpoints, `throttle:60,1` on all endpoints
- All responses wrapped through `UserResource` (JsonResource)
- An OpenAPI 3.0 spec via `php artisan laraattr:docs`

---

Table of contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Quick start](#quick-start)
- [Core concept — why a separate Schema class?](#core-concept--why-a-separate-schema-class)
- [Attribute reference](#attribute-reference)
    - [`#[ApiResource]`](#apiresource)
    - [`#[Schema]`](#schema)
    - [`#[Validate]`](#validate)
    - [`#[Fillable]`](#fillable)
    - [`#[Hidden]`](#hidden)
    - [`#[Middleware]`](#middleware)
    - [`#[With]`](#with)
    - [`#[Searchable]`](#searchable)
    - [`#[Sortable]`](#sortable)
    - [`#[Paginate]`](#paginate)
    - [`#[Cache]`](#cache)
    - [`#[Event]`](#event)
    - [`#[SoftDelete]`](#softdelete)
- [Auto-generated routes](#auto-generated-routes)
- [Query features](#query-features)
- [Response caching](#response-caching)
- [Event dispatch](#event-dispatch)
- [Soft delete](#soft-delete)
- [OpenAPI doc generation](#openapi-doc-generation)
- [Configuration](#configuration)
- [`route:cache` compatibility](#routecache-compatibility)
- [Security notes](#security-notes)
- [Testing](#testing)
- [Troubleshooting](#troubleshooting)
- [Known limitations](#known-limitations)
- [Requirements](#requirements)
- [License](#license)

---

Installation
------------

[](#installation)

```
composer require devvelvet/laraattr
```

The service provider is registered automatically via Laravel's package auto-discovery — no manual registration step required.

To publish the config file:

```
php artisan vendor:publish --tag=laraattr-config
```

This creates `config/laraattr.php`.

---

Quick start
-----------

[](#quick-start)

### 1. Create a Schema class

[](#1-create-a-schema-class)

`app/Schemas/UserSchema.php`:

```
