CodeIgniter Forums
How to validate data with in_list inside model - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=31)
+--- Thread: How to validate data with in_list inside model (/showthread.php?tid=79090)



How to validate data with in_list inside model - llyimo1920 - 04-18-2021

I am trying to do clean-up in my controllers by moving my validation rules to the model class but unfortunately i came to realize there is no clear documentation on how to pass values to be tested into the validation rules. I have been searching for a solution without luck.

NB: the in_list values are expected to come from the database, so the list is dynamic 

PHP Code:
protected $validationRules = [
    'id' => 'required|in_list[list_of_ids_from_db]'
]; 



RE: How to validate data with in_list inside model - iRedds - 04-18-2021

Solution: You can always write your own validation rule.


RE: How to validate data with in_list inside model - llyimo1920 - 04-18-2021

(04-18-2021, 08:26 PM)iRedds Wrote: Solution: You can always write your own validation rule.
Thank you
I have considered doing so but for now I'm looking for insights from the community first.


RE: How to validate data with in_list inside model - ojmichael - 04-18-2021

I think that's what the is_not_unique method is for.

PHP Code:
protected $validationRules = [
    'id' => 'required|is_not_unique[table.id]'
]; 



RE: How to validate data with in_list inside model - llyimo1920 - 04-19-2021

(04-18-2021, 11:36 PM)ojmichael Wrote: I think that's what the is_not_unique method is for.

PHP Code:
protected $validationRules = [
    'id' => 'required|is_not_unique[table.id]'
]; 
i never thought of this rule that way.
Thanks for the advice