Reputation: 3834
When using the RevisionableTrait, how can you trigger it to save a revision for a specific model, all this done from a Controller.
An user sends an email (this action doesn't CRUD any model), but I want to track this action. So I do something like:
Action::make('send email', $user, $email, $time, $from, $to, $subject, ....)
Reason: I want to save the revision when doing something other that the CRUD methods that Revisionable supports. So, I need to trigger it manually.
Example: This package does exactly what I am describing. I can create an Activity whenever is needed. Plus appending some extra information.
Example: I want to create a revision even if the Model doesn't changes!. Some actions that could trigger this could be: a user sends an email, a user looks at an email draft. So, from the Controller I need to log/register that action and save it. Is that possible?
Revisionable looks like it doesn't have an event listening to custom triggers. Am I wrong ?, is there a workaround ?
Notes:
Upvotes: 1
Views: 471
Reputation: 9146
The revisionable documentation tells you exactly what you need to do, add the trait to your model:
class YourModelHere extends Eloquent {
use \Venturecraft\Revisionable\RevisionableTrait;
public static function boot()
{
parent::boot();
}
// other model code goes here
}
It woks by calling boot methods when saving, saved, creating, and updating.
Is also provides events that you can tie into:
Events
Every time a model revision is created an event is fired. You can listen for
revisionable.created
,revisionable.saved
orrevisionable.deleted
.
Upvotes: 0