Welcome Guest, Not a member yet? Register   Sign In
How to validate data with in_list inside model
#1

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]'
]; 
Reply
#2

Solution: You can always write your own validation rule.
Reply
#3

(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.
Reply
#4

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

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

(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
Reply




Theme © iAndrew 2016 - Forum software by © MyBB