I am using Laravel Nova v4.0, and am trying to resize the image before uploading it to server. Suppose someone selects an image of 8mb which is very heavy, I need to resize this image to somewhere around 100kb or 200kb and then upload to server.
I know that I can use validation, but I want the user to upload any size and the let the code resize the image. Is it possible?
I have tried this:
Image::make('Image', 'meta->image_path')
->required()
->prunable()
->resize(100, 100, function ($constraint) {
$constraint->aspectRatio();
})
->disk(\App\Models\SomeModel::disk())
->path(\App\Models\SomeModel::uploadPath())
->maxWidth(150)
// ->rules("image", "max:200", "min:100")
->disableDownload()
->preview(function () {
return $this->logo_url;
})
->thumbnail(function () {
return $this->logo_url;
})
->displayUsing(function () {
return $this->logo_url;
}),
But i'm getting this error:
Method Laravel\Nova\Fields\Image::resize does not exist.