Download the PHP package uteq/laravel-model-actions without Composer

On this page you can find all versions of the php package uteq/laravel-model-actions. 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 laravel-model-actions

Magically adds actions to a model

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

This package will magically add actions to a model. Simply adding the WithActions trait:

Add the trait to your model

And than use it in all sorts of ways:

Whenever you need to call a method on a model that does not (yet) have an active record in the database, you can also use this static method.

This package was inspired by this read about OOP: https://www.tonysm.com/when-objects-are-not-enough/#objects-in-the-large Especially the last part about actions being added to a model made sense to me. This will keep your models clean, and your actions separated.

The idea behind this package is that adding actions makes your application more scalable. 'Grouping' these actions by adding them to a model, makes it easier to comprehend where the action is for. It is more declarative having your model $user->action() perform an action than having the action out of the blue. To create more context you would have to always prefix your action UserCreateAction for example.

Not convinced about using Actions in your application? Read this excellent blog post of Brent from Spatie.be https://stitcher.io/blog/laravel-beyond-crud-03-actions

You will need php 8.0

Installation

You can install the package via composer:

You can publish the config file with:

This is the contents of the published config file:

Usage

On your model

Add the WithActions trait to the model

Directory

The actions should be added in the following folder structure

After that you can always access the actions from your model:

This is how an action class looks like:

As you can see the $user will automatically be injected into the __invoke method. The system knows the user because you are calling in from the user. Please note that the model is always the first parameter.

The name of the Action class will be used as the method name. So a class UpdateImage will be accessible using User::action()->updateImage($input);

Dependency injection in Actions

Dependency injection in the __construct of the action is by default. So you can do this:

Parameter binding

Parameter binding for model actions is pretty straight forward. We have Named parameters (see below) and simply using the given order:

Named parameters

Utilizing php 8's named paramters you are able to be very strict into what your action class accepts.

Examples

Apply with actions to all your models

A convenient way to add the WithActions to all your Models is by simply extending the Eloquent Model class and extend upon that class.

Testing

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.


All versions of laravel-model-actions with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
illuminate/contracts Version ^8.0
spatie/laravel-package-tools Version ^1.1
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 uteq/laravel-model-actions contains the following files

Loading the files please wait ....