Download the PHP package narcisonunez/laravel-actionable-model without Composer
On this page you can find all versions of the php package narcisonunez/laravel-actionable-model. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download narcisonunez/laravel-actionable-model
More information about narcisonunez/laravel-actionable-model
Files in narcisonunez/laravel-actionable-model
Package laravel-actionable-model
Short Description Allow actions in your laravel model
License MIT
Homepage https://github.com/narcisonunez/laravel-actionable-model
Informations about the package laravel-actionable-model
Allow actions in your laravel model
Allow models to perform or receive actions.
Installation
You can install the package via composer:
You can publish and run the migrations with:
Basic Setup
Register your actions
Add your action in your AppServiceProvider
You can implement your own class extending ActionableTypeRecord
to add more logic to your records.
Ex. icon
method to get that specific action type icon.
Now, Any kudos
action will have a method named icon
.
Your actions will be used as dynamic method calls. See below.
Create a new Actionable Action Type (OPTIONAL)
Add aliases to your models (OPTIONAL)
Add your aliases in your AppServiceProvider
Storing aliases in the database will prevent losing the reference if you move your models to another directory.
Update existing models references to use the new alias
In case you already have data in the database, after adding the aliases you can run:
If you want just to update a specific value
To update all your existing records.
Traits
A model that can perform actions you need to include:
The model that can receive the actions must implement CanBeActionable
Basic Usage
Perform an action
Check if the action was already made
Toggle your actions
Manually delete an action (See Toggle above)
Get all the actions
- Available methods -
Method | Description |
---|---|
get | Returns a collection of ActionableTypeRecord |
count | Returns the number of records |
given | Filters all the records where the current model performed the actions |
received | Filters all the records where the current model received the actions |
ofType | Filters by the actionType |
by | Filters all the actions in the current model where the model passed to this method performed the action |
latest | Get the collection sorted by the latest ones. |
Actionable Record
The methods above will return a collection of ActionableRecord
.
The access the owner or the actionable models, you can do it like this:
💖 Support the development
Do you like this project? Support it by donating
- PayPal: Donate
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-actionable-model with dependencies
spatie/laravel-package-tools Version ^1.4.3
illuminate/contracts Version ^8.0