PHPackages                             jojomak13/laravel-attributes - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. jojomak13/laravel-attributes

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

jojomak13/laravel-attributes
============================

This package provides the ability to create custom attributes for Laravel controllers. You can use these attributes to add functionality like authorization, validation, or any other custom behavior to your controller methods.

v1.0.0(1y ago)54MITPHPPHP &gt;=8.0

Since Jan 18Pushed 1y ago1 watchersCompare

[ Source](https://github.com/jojomak13/laravel-attributes)[ Packagist](https://packagist.org/packages/jojomak13/laravel-attributes)[ RSS](/packages/jojomak13-laravel-attributes/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (3)Versions (2)Used By (0)

[![Packagist License](https://camo.githubusercontent.com/048b672d090ef8020cbc315f5213f2bccc231a52e3b137399b697b1df5c60116/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6a6f6a6f6d616b31332f6c61726176656c2d61747472696275746573)](https://camo.githubusercontent.com/048b672d090ef8020cbc315f5213f2bccc231a52e3b137399b697b1df5c60116/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6a6f6a6f6d616b31332f6c61726176656c2d61747472696275746573)[![Packagist Downloads](https://camo.githubusercontent.com/f1c4b6cebd5b9ccad9b31eddab0c795db8b79c455896a9b61f3a5fc3a0551a46/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64642f6a6f6a6f6d616b31332f6c61726176656c2d61747472696275746573)](https://camo.githubusercontent.com/f1c4b6cebd5b9ccad9b31eddab0c795db8b79c455896a9b61f3a5fc3a0551a46/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64642f6a6f6a6f6d616b31332f6c61726176656c2d61747472696275746573)[![Packagist Version](https://camo.githubusercontent.com/d1a0914971d77d86fa2204735fd5c38d0f41c1cb8ff30eaf264667e4c71c4237/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a6f6a6f6d616b31332f6c61726176656c2d61747472696275746573)](https://camo.githubusercontent.com/d1a0914971d77d86fa2204735fd5c38d0f41c1cb8ff30eaf264667e4c71c4237/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a6f6a6f6d616b31332f6c61726176656c2d61747472696275746573)[![Packagist Stars](https://camo.githubusercontent.com/0e90d4480c1374e65233ffae64750bb1fe12fa7e378a8b0e4a0d2c0af5203499/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f73746172732f6a6f6a6f6d616b31332f6c61726176656c2d61747472696275746573)](https://camo.githubusercontent.com/0e90d4480c1374e65233ffae64750bb1fe12fa7e378a8b0e4a0d2c0af5203499/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f73746172732f6a6f6a6f6d616b31332f6c61726176656c2d61747472696275746573)

Laravel Attributes
==================

[](#laravel-attributes)

This package provides the ability to create custom attributes for Laravel controllers. You can use these attributes to add functionality like authorization, validation, or any other custom behavior to your controller methods.

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

[](#installation)

```
composer require jojomak13/laravel-attributes
```

Basic Usage
-----------

[](#basic-usage)

Let's walk through creating a custom attribute for authorization using Laravel policies.

### Creating an Attribute

[](#creating-an-attribute)

First, generate a new attribute class using the provided artisan command:

```
php artisan make:attribute PolicyAttribute
```

This will create a new attribute class in the `App\Attributes` namespace.

### Attribute Structure

[](#attribute-structure)

Each attribute class contains two main methods:

1. `__construct`: Defines the parameters you want to pass to your attribute
2. `handle`: Contains the logic for your attribute's functionality

### Example Implementation

[](#example-implementation)

Here's an example of implementing a policy-based authorization attribute:

```
