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

Ignore_value should be the value of ID, how do I get it? #772

Closed
jinmarcus opened this issue Oct 12, 2017 · 5 comments
Closed

Ignore_value should be the value of ID, how do I get it? #772

jinmarcus opened this issue Oct 12, 2017 · 5 comments

Comments

@jinmarcus
Copy link

jinmarcus commented Oct 12, 2017

In the model file

protected $validationRules = [
    'css' => 'required|is_unique[dbname.css, id, ignore_value]'
 ];

Ignore_value should be the value of ID, how do I get it?

@gustavojm
Copy link
Contributor

Something like this:

protected $validationRules = [
'css' => 'required|is_unique[dbname.css, id, '. $this->request->input->getPost('id'). ' ]'
];

@lonnieezell
Copy link
Member

That's a rule that might be better done in the controller itself, honestly. There are times when 2 layers of validation is a good thing, and you might find that you prefer it all in the controller. Personally, I do validation in the model just to ensure it's valid data. In the controller is validation that determines whether it should be allowed to be stored. In the controller it's also easier to catch the validation issues and redirect back.

@jinmarcus
Copy link
Author

I know in controller is ok, but I like to write the basic logic only in the controller, and pass the database processing to the model. If the model can't get the value of ID, then the model becomes meaningless.

@lonnieezell
Copy link
Member

If you have suggestions on how to handle that, I'm open to hearing them.

@jinmarcus
Copy link
Author

In the model.php page, automatically retrieve the ignored values instead of passing the ignored values.

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

No branches or pull requests

3 participants