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

On this page you can find all versions of the php package hosnyadeeb/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

Laravel Model Actions

A Laravel package for generating action classes for Eloquent models with built-in CRUD operations.

Features

Installation

Install the package via Composer:

The package will automatically register its service provider.

Publish Assets (Optional)

Publish Configuration

Publish Stubs for Customization

This allows you to customize the generated action classes, including the Base classes.

Once published, you can edit the files in stubs/model-actions/. The command will automatically use these custom stubs when generating new actions.

Example:

Usage

Generate Actions for a Model

This will create the following files in app/Actions/User/:

Generate a Custom Action

Create a single custom action for a model:

This creates app/Actions/User/UserActivateAction.php with hooks ready to use.

Running Actions

There are three ways to execute an action:

1. Static Method (Recommended)

2. Helper Function

3. Instance Method

Customizing Actions

Using Custom Query Builder

The IndexAction provides a customBuilder method for complex queries:

Overriding Store/Update Logic

In Controllers

Lifecycle Hooks

All actions support before(), after(), and onError() hooks for injecting custom logic:

Using Hooks

Hook Execution Order

  1. before() - Runs before the main action logic
  2. handle() - Main action logic executes
  3. after($result) - Runs after successful execution (can modify result)
  4. onError($e) - Runs if an exception occurs (then re-throws)

Custom Actions

Create custom business logic actions beyond CRUD operations.

Creating a Custom Action

Use the artisan command:

Or create manually by extending the base Action class:

Running Custom Actions

Composite Actions

Chain multiple actions together:

Using Traits in Custom Actions

Combine multiple traits for enhanced functionality:

Query Filters

The Filterable trait provides powerful search, sort, and date filtering capabilities for Index actions.

Using Filters

Available Filter Parameters

Parameter Description Example
search or q Search term ?search=john
sort or order_by Column to sort by ?sort=name
direction or order_dir Sort direction (asc/desc) ?direction=asc
date_from or from Filter from date ?date_from=2024-01-01
date_to or to Filter to date ?date_to=2024-12-31
Any other key Where condition ?status=active&role=admin

Usage in Controller

Searching Relationships

Define relationship columns with dot notation:

Bulk Actions

Perform operations on multiple records at once.

BulkDeleteAction

BulkUpdateAction

Configuration

After publishing the config file, you can customize:

Customizing Stubs

After publishing stubs, you can find them in stubs/model-actions/. Modify these files to change the generated action structure:

Directory Structure

After generating actions, your project will have:

Testing

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.1
illuminate/console Version ^10.0|^11.0|^12.0
illuminate/database Version ^10.0|^11.0|^12.0
illuminate/filesystem Version ^10.0|^11.0|^12.0
illuminate/support Version ^10.0|^11.0|^12.0
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 hosnyadeeb/laravel-model-actions contains the following files

Loading the files please wait ...