PHP Artisan Make: Prośba
php artisan make:request User\CreateUserRequest
Encouraging Echidna
php artisan make:request User\CreateUserRequest
use Illuminate\Support\Facades\Validator;
$validator = Validator::make($request->all(), [
'photos.profile' => 'required|image',
]);
use Illuminate\Http\Response;
protected function failedValidation(\Illuminate\Contracts\Validation\Validator $validator)
{
$response = new Response(['error' => $validator->errors()->first()], 422);
throw new ValidationException($validator, $response);
}
public function response(array $errors)
{
// Always return JSON.
return response()->json($errors, 422);
}