Assume you have a Post model. Each visitor on your site can edit any post, but before you want to publish the change to your website, you want to approve it first. By adding the \Victorlap\Approvable\Approvable trait to your Post model, when a visitor makes a change, a change request gets stored in the database. These changes can then later be applied, or denied by administrators. The currentUserCanApprove method can be used to determine who is authorized to make a change.
Making a change to a model by a user who can approve does not change.
$post->title="Very Good Post";$post->save(); // This still works!
Making a change by an unauthorized user works the same.
$post->title="Very Good Post";$post->save(); // Post remains with the old title in the database, however a change request is now also present.
You can retrieve a list of attributes that have pending changes by using
Or check if a certain attribute has pending changes
Scopes have been defined to quickly see approvals in different states. For example if you wnat to show administrators a list with changes that can be accepted you can use the open scope. Other scopes are accepted, rejected and ofClass.