Hello Sir, I have a suggestion, 1. I really don't trust sellers to have the patience to make images square and maximum of 1024MB, can we use a small library that helps compress images to a certain size and also crop a square of the product? just like the image cropper but rigid square size. 2. is it possible for admin to convert a regular customer to a seller with just one click? or the customer who chooses to become a seller will just have to create a new seller account?
Hello friend. You' re right. If you don't trust a user (sellers) while they are creating a product and trying to upload an image which is not square and that image may has large size. You can use the following trick to prevent that image to excess 1024MB by using Image intervention package for Laravel. use Intervention\Image\Facades\Image; //new ..................... $product_image = null; //Upload product image if($request->hasFile('product_image')){ $path = "images/products/"; $file = $request->file('product_image'); $filename = 'PIMG_'.time().uniqid().'.'.$file->getClientOriginalExtension(); $maxWidth = 1080; //new $maxHeight = 1080; //new $full_path = $path.$filename; //new $image = Image::make($file->path()); //new // $upload = $file->move(public_path($path),$filename); // replaced by below lines $image->height() > $image->width() ? $maxWidth = null : $maxHeight = null; //new $image->resize($maxWidth, $maxHeight, function ($constraint) { //new $constraint->aspectRatio(); $constraint->upsize(); }); $upload = $image->save($full_path); //new if( $upload ){ $product_image = $filename; } } Thats it!! In order to prevent a large size of an image, just, try to make small values on maxWidth and maxHeight. For converting custom account to seller account with one click, we will see that in next videos. Thank you. Happy coding.....
i'm stuck, console keeps giving me 500 internal server error then Uncaught TypeError: Cannot read properties of undefined (reading 'errors') at Object.error (add:682:54)
Because your save $product->product_image = $request->product_image; intead of saving directly $product->product_image = $product_image;. You have already write in the top $product_image = $filename;