Laravel 10: implementing multiple form submissions leading to unexpected validation behavior
After trying multiple solutions online, I still can't figure this out. I've been researching this but I tried several approaches but none seem to work... I'm currently working with an scenario with handling multiple form submissions in a Laravel 10 application, specifically related to validation. I have a form that allows users to submit multiple entries at once, and Iโm using a custom request validation class. The question arises when I try to validate each entry individually; the validation seems to unexpected result for valid entries, returning unexpected behavior messages. Hereโs the relevant part of my form submission logic: ```php public function store(MultipleEntriesRequest $request) { $entries = $request->input('entries'); // Array of entries foreach ($entries as $entry) { $newEntry = new Entry(); $newEntry->fill($entry); if (!$newEntry->save()) { return back()->withErrors('Could not save entry: ' . $entry['name']); } } return redirect()->route('entries.index')->with('success', 'Entries saved successfully!'); } ``` And hereโs my custom request validation: ```php public function rules() { return [ 'entries.*.name' => 'required|string|max:255', 'entries.*.email' => 'required|email|unique:users,email', ]; } ``` Iโm passing in an array of entries, but sometimes I see validation errors for entries that should be valid, especially for the `email` field. The unique validation rule seems to be causing the scenario because it checks the users table, and since Iโm submitting multiple entries in quick succession, it fails to validate against entries that are not yet saved in the database. I tried using the `ignore` method in the validation rule like this: ```php 'entries.*.email' => 'required|email|unique:users,email,NULL,id', ``` But it didn't resolve the scenario. How can I handle this scenario effectively so that valid entries do not unexpected result validation due to unique constraints? Are there best practices or patterns in Laravel that I should consider for mass submissions like this? I'm working on a service that needs to handle this. What's the best practice here? Any ideas what could be causing this? The stack includes Php and several other technologies. Cheers for any assistance! This is part of a larger application I'm building. Any ideas what could be causing this?