laravel-learn-bbs/app/Http/Requests/Api/ImageRequest.php

36 lines
742 B
PHP
Raw Permalink Normal View History

2018-06-10 09:25:41 +00:00
<?php
namespace App\Http\Requests\Api;
class ImageRequest extends FormRequest
{
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
$rules = [
'type' => 'required|string|in:avatar,topic',
];
if ($this->type == 'avatar') {
$rules['image'] = 'required|mimes:jpeg,bmp,png,gif|dimensions:min_width=200,min_height=200';
} else {
$rules['image'] = 'required|mimes:jpeg,bmp,png,gif';
}
return $rules;
}
public function messages()
{
return [
'image.dimensions' => '图片的清晰度不够,宽和高需要 200px 以上',
];
}
}