0

I have a dynamically generated form. I use an array to retrieve all the data. Something like this:

<input type="text" class="dynamically-generated" name="ItemArray[]">
<!-- This code as many times as desired -->

Now I want these inputs to be validated in the request:

public function rules()
{
    return [
     'Item' => 'integer'
    ];
}

I need however to do this in each of the elements in the array. This would be pretty easy in plain PHP. How is this possible in Laravel? I want to do this properly

1 Answer 1

1

You're more than likely going to validate these inputs before storing them. So you could something like the following.

/**
 * Store a new something.
 *
 * @param  Request  $request
 * @return Response
 */
public function store(Request $request)
{
    $this->validate($request, [
        'item' => 'required|max:255'
    ]);

    // The something is valid, store in database...
}

The one you are using above is for complex validation scenarios.

You can read more on Validation in Laravel here

Sign up to request clarification or add additional context in comments.

Comments

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.