1

I have a page which have a select with name="action_id[]", the user can add another action by clicking on a button. The new action is another select with name="action_id[]" so I end up with a view that has many selects with the same name.

when the user submits the form, I do this in the controller:

$actions = Input::get('action_id')

and I get an array.

How to validate these values? They have the same name, so I can not do this because it validates only one action_id:

$validation = Validator::make($actions, Actions::rules)

where Actions::rules is

public static $rules = array(
    'action_id' => 'required|integer|not_in:0'
);

How can I validate the array of actions?

1 Answer 1

2

you could do it with a foreach():

foreach ($actions as $singleAction) {
    $validation = Validator::make($singleAction, Actions::rules);
    // do whatever foo with $validation
}

this assumes that your $actions is the array returned by the form. It should look like this:

array(
    0 => 'action1',
    1 => 'action2',
  // etc
);
Sign up to request clarification or add additional context in comments.

2 Comments

I got this exception Argument 1 passed to Illuminate\Validation\Factory::make() must be of the type array, string given
+1 it works now, I will accept when the system allows

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.