Validate in Laravel, That at Least One Checkbox is Checked
If you have a form with multiple checkboxes (categories, tags, …) and you want to be sure, that at lease on checkbox is checked, you can add this validation:
public function store(Request $request)
{
$validatedData = $request->validate([
'category' => 'required',
]);
// more code
}
The ‘required’ validation checks, that there is at least one checked checkbox – all you need.
Related Posts
- Validate in Laravel, That Checkbox IDs are Valid
- Install Sentry on Ubuntu 18.04 Using Nginx and Let's Encrypt Certificates
- Fix Laravel Forge Site Creation Problems
- Tutorial: Ubuntu 18.04 LAMP Setup for WordPress
- Fix WordPress Subfolder 404 Errors When Using Laravel Forge
- Allow Empty Values when Validating URL or Email in Laravel