Support the ongoing development of →
Validation Laravel Requests
Last updated 1 year ago.

Hi Georg!

First of all, if you use the Mass Assignment for Storing/Updating Model's Data, every extra field passed in the storing/updating data will be automatically ignored.

So, in order to manage also the validation for your JSON Data, i would suggest you to use the FormRequest Class in order to validate the input as you want. As you can see in the example, you can use the dot notation to validate JSON nested data.

php artisan make:request StoreYourModelRequest

 * Get the validation rules that apply to the request.
 * @return array
public function rules()
    return [
        'title' => 'required|unique:posts|max:255',
        '' => 'required',
        'author.description' => 'required',

And so, in your controller, you can use it:

public function store(StoreYourModelRequest $request)
    YourModel::store($request->validated()); // Validated method return ONLY validated data, extra will be ignored.

Hope it helps!



Sign in to participate in this thread!


Your banner here too?


We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 - All rights reserved.