이전 유효성 검사( 차원 ) - Laravel
7492 단어 laravelprogrammingphpwebdev
소스를 방문하십시오 :-
https://laravel.com/docs/9.x/validation#rule-dimensions
https://mattstauffer.com/blog/image-dimension-validation-rules-in-laravel-5-3/
In Laravel 5.3, we have a new validation option: image dimensions for image uploads
The validation rule is called dimensions, and you can pass the following parameters to it
min_width: Images narrower than this pixel width will be rejected
max_width: Images wider than this pixel width will be rejected
min_height: Images shorter than this pixel height will be rejected
max_height: Images taller than this pixel height will be rejected
width: Images not exactly this pixel width will be rejected
height: Images not exactly this pixel height will be rejected
ratio: Images not exactly this ratio (width/height, expressed as "width/height") will be rejected
public function postImage(Request $request)
{
$this->validate($request, [
'avatar' => 'dimensions:min_width=250,min_height=500'
]);
// or...
$this->validate($request, [
'avatar' => 'dimensions:min_width=500,max_width=1500'
]);
// or...
$this->validate($request, [
'avatar' => 'dimensions:width=100,height=100'
]);
// or...
// Ensures that the width of the image is 1.5x the height
$this->validate($request, [
'avatar' => 'dimensions:ratio=3/2'
]);
}
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\Rule;
Validator::make($data, [
'avatar' => [
'required',
Rule::dimensions()->maxWidth(1000)->maxHeight(500)->ratio(3 / 2),
],
]);
나는 당신이 코드를 즐겼기를 바라며 행복한 코드를 기원합니다.
Reference
이 문제에 관하여(이전 유효성 검사( 차원 ) - Laravel), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/morcosgad/old-validation-dimensions-laravel-3la4텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)