Download the PHP package artificertech/eloquent-attribute-middleware without Composer

On this page you can find all versions of the php package artificertech/eloquent-attribute-middleware. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package eloquent-attribute-middleware

EloquentAttributeMiddleware

Latest Version on Packagist Total Downloads Build Status StyleCI

This package enables you to define middleware classes for your Eloquent model accessors and mutators using php 8 Attributes. This allows you to reuse complex code for your computed attributes. Take a look at contributing.md to see a to do list.

Requirements

php ^8.0, Laravel ^8

Installation

Via Composer

Usage

Accessors

create your accessor middleware class using laravel artisan

Configure your accessor middleware. Accessor middlware should modify the response of the $next() callback and return the modified value.

Add the middleware functionality to your Eloquent Model

Now any time you retrieve the name attribute it will be Uppercase

Execution Order

Accessors run in order of definition. In the following example the user 'name' attribute is stored in the database as 'Cole Shirley'

Execution order:

  1. the Upper __invoke method is called first which retrieves the value of the next callback
  2. the AppendTestString __invoke method is then called which retireves the value of the next callback
  3. the getNameAttribute method is called with the value 'Cole Shirley' from the stored model attributes
  4. that value is passed back to AppendTestString which then concatenates '_test' onto the value
  5. the modified string is passed back to Upper which makes the entire string uppercase
  6. the finalized string is passed back to the implemenation

Mutators

create your mutator middleware class using laravel artisan

Configure your mutator middleware. Mutator middlware should modify $value parameter before passing it to the $next() callback

Add the middleware functionality to your Eloquent Model

Now when you set the name attribute it will be lowercased

Execution Order

Mutators run in order of definition

Execution order:

  1. the Lower __invoke method is called first with the value 'Cole Shirley'
  2. the WithoutExtraWhitespace __invoke method is called with the value 'cole shirley'
  3. the setNameAttribute is called with the value 'cole shirley'
  4. if the setNameAttribute has a return value it is passed back to the implementation

Practical example: Caching model info from api

For most situations you should be able to use normal accessor and mutator functionality. However if you find yourself setting up complicated accessors or mutators repeatedly you may consider extracting that functionality into accessor and mutator middleware. A great example is if you want to cache data related to a model from an external api

Change log

Please see the changelog for more information on what has changed recently.

Testing

Contributing

Please see contributing.md for details and a todolist.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

MIT. Please see the license file for more information.


All versions of eloquent-attribute-middleware with dependencies

PHP Build Version
Package Version
Requires illuminate/support Version ~8|~9
php Version ^8.0.2
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package artificertech/eloquent-attribute-middleware contains the following files

Loading the files please wait ....