Answers for "laravel validation in array"

PHP
6

laravel image validation

'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
Posted by: Guest on May-30-2020
1

laravel validation array

$data = $request->validate([
    "name"    => "required|array|min:3",
    "name.*"  => "required|string",
]);
Posted by: Guest on June-08-2021
8

if any error in blade laravel

@if ($errors->any())
     @foreach ($errors->all() as $error)
         <div>{{$error}}</div>
     @endforeach
 @endif
Posted by: Guest on November-01-2020
2

validate each value from array laravel

$validator = Validator::make($request->all(), [
    "names"    => "required|array|min:3",
    "names.*"  => "required|string|distinct|min:3",
]);
Posted by: Guest on November-12-2020
1

in_array validation laravel

I found a better solution. The validate in_array expects the array to be one of
the parameters in the request. The in: answer will not work if you have 
commas in the array. To use the in_array without having to create a new rule 
you can simply do: ( Make sure you include the .* at the end )

$this->allslots = array('10:00:00', '10:10:00', '10:20:00', '10:30:00', '10:40:00', '10:50:00', '11:00:00', '11:10:00', '11:20:00', '11:30:00', '11:40:00', '11:50:00', '12:00:00', '12:10:00', '12:20:00', '12:30:00', '12:40:00', '12:50:00', '13:00:00', '13:10:00', '13:20:00', '13:30:00', '13:40:00', '13:50:00', '14:00:00', '14:10:00', '14:20:00', '14:30:00', '14:40:00', '14:50:00', '15:00:00', '15:10:00', '15:20:00', '15:30:00', '15:40:00', '15:50:00', '16:00:00', '16:10:00', '16:20:00', '16:30:00', '16:40:00', '16:50:00');

$request['allslots'] = $this->allslots;

validate($request, [
  'field' => 'required|in_array:allslots.*',
]);
Posted by: Guest on December-01-2020
7

laravel validation example

//import		
		use Illuminate\Support\Facades\Validator;
	
		// single var check
        $validator = Validator::make(['data' => $value],
            ['data' => 'string|min:1|max:10']
        );
        if ($validator->fails()) {
            // your code
        }

        // array check
        $validator = Validator::make(['data' => $array],
            ['email' => 'string|min:1|max:10'],
            ['username' => 'string|min:1|max:10'],
            ['password' => 'string|min:1|max:10'],
            ['...' => '...']
        );

        if ($validator->fails()) {
            // your code
        }
Posted by: Guest on April-17-2020

Code answers related to "laravel validation in array"

Browse Popular Code Answers by Language