Eimhin Walsh
0
Q:

laravel image validation

'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
0
$this->validate($request, ['file' => 'image|mimes:jpeg,png,jpg,gif,svg|max:2048',]);
1
		//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
        }
5
/**
 * Store a new blog post.
 *
 * @param  Request  $request
 * @return Response
 */
public function store(Request $request)
{
    $validatedData = $request->validate([
        'title' => 'required|unique:posts|max:255',
        'body' => 'required',
    ]);

    // The blog post is valid...
}
1

New to Communities?

Join the community