Quantcast
Channel: User totymedli - Stack Overflow
Viewing all articles
Browse latest Browse all 55

Answer by totymedli for Laravel 5: Request validate multidimensional array

$
0
0

Laravel 5.5 or newer

You can use the same array validation syntax that is available in the Validator, so the code in the question now works:

public function rules(){    return ['id' => 'required','slide' => 'array|min:1','slide.*.title' => 'required|max:255','slide.*.description' => 'required|max:255',    ];}

Laravel 5.4 or older

Disclaimer: This solution was posted in the question by Alexej. Since answers shouldn't be shared in the question body and the OP seems to be inactive, I repost his answer as a community wiki for future readers:

I've found the solution by getting the slide array and loop through it.

public function rules(){    $rules = ['id' => 'required','slide' => 'array|min:1',    ];    foreach($this->request->get('slide') as $key => $val){        $rules['slide.'.$key.'.title'] = 'required|max:255';        $rules['slide.'.$key.'.description'] = 'required|max:255';    }    return $rules;}

Viewing all articles
Browse latest Browse all 55

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>