Skip to content

Instantly share code, notes, and snippets.

@neilcrookes
Created October 29, 2015 20:13
Show Gist options
  • Save neilcrookes/1f7fa60136f6adebde65 to your computer and use it in GitHub Desktop.
Save neilcrookes/1f7fa60136f6adebde65 to your computer and use it in GitHub Desktop.
Example syntax for validating multi-record forms
<?php
class ProductController {
/**
* Store a new product that belongs to multiple categories.
*
* @param Request $request
* @return Response
*/
public function store(Request $request)
{
$this->validate($request, [
'name' => 'required|unique:products|max:255',
'description' => 'required',
'category.*.id' => 'exists:categories'
]);
// The product is valid, store in database...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment