Last active
November 15, 2022 23:45
-
-
Save Zakarialabib/7985166c5dab381d41b2cb9ee81c6c68 to your computer and use it in GitHub Desktop.
Revisions
-
Zakarialabib renamed this gist
Nov 15, 2022 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
Zakarialabib created this gist
Nov 15, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,54 @@ public function saveImage() { if ($this->image_url) { $image = file_get_contents($this->image_url); $imageName = Str::random(10).'.jpg'; Storage::disk('local_files')->put('products/'.$imageName, $image, 'public'); $this->product->image = $imageName; }elseif ($this->image) { $image = $this->image; $imageName = Str::slug($this->product->name).'.'.$this->image->extension(); $img = ImageIntervention::make($image->getRealPath())->resize(1500, 1500, function ($constraint) { $constraint->aspectRatio(); }); $img->stream(); Storage::disk('local_files')->put('products/'.$imageName, $img, 'public'); $this->product->image = $imageName; } // gallery image if ($this->gallery != null) { $gallery = []; foreach ($this->gallery as $key => $value) { $image = $value; $imageName = Str::slug($this->product->name).'-'.$key.'.'.$value->extension(); $img = ImageIntervention::make($image->getRealPath())->resize(1500, 1500, function ($constraint) { $constraint->aspectRatio(); }); $img->stream(); Storage::disk('local_files')->put('products/'.$imageName, $img, 'public'); $gallery[] = $imageName; } $this->product->gallery = json_encode($gallery); } $this->product->save(); $this->alert('success', __('Product image updated successfully.')); $this->emit('refreshIndex'); $this->imageModal = false; }