Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow models to require approval only when needed #10

Closed
wants to merge 25 commits into from

Conversation

mankowitz
Copy link

For my use case, I had many crud operations already defined for my models, and only wanted approval in certain circumstances. With this PR, approval can be turned off and on as needed by attaching the trait MayBeApproved.

namespace App;

use \Illuminate\Database\Eloquent\Model;
use Cjmellor\Approval\Concerns\MayBeApproved;

class Site extends Model 
{
    use MayBeApproved;
}

Now, in normal use, if I want to update a particular attribute of a site, it works normally (return true). When I execute the command requireApproval() and then update the site, it return false and inserts the Morph into the approvals table. I can turn the requirement off again with requireApproval(false)

>>> Site::find(109)->update(['zip'=>rand()]);
[!] Aliasing 'Site' to 'App\Site' for this Tinker session.
=> true

>>> Site::requireApproval()
=> null

>>> Site::find(109)->update(['zip'=>rand()]);
=> false

>>> Site::requireApproval(false)
=> null

>>> Site::find(109)->update(['zip'=>rand()]);
=> true

In addition, I can also commit changes as follows

Site::find(109)->approvals()->first()->commit(); // commit the first approval
Site::find(109)->approvals->each->commit()    // commit all approvals

@cjmellor
Copy link
Owner

cjmellor commented Sep 1, 2022

Hi,

Thanks for the PR.

I am not going to be approving it as it is not achieving anything I want for this package.

My suggestion is to fork this repo and use it in your project as what you're after is unique just to you.

Thanks.

@cjmellor cjmellor closed this Sep 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants