fix: adding user avatar editing
This commit is contained in:
44
site/app/Livewire/Artist/Avatar.php
Normal file
44
site/app/Livewire/Artist/Avatar.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Artist;
|
||||
|
||||
use Livewire\Component;
|
||||
use Livewire\WithFileUploads;
|
||||
use Spatie\Image\Image;
|
||||
use Intervention\Image\Facades\Image as InterventionImage;
|
||||
use ImageOptimizer;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Validation\Rules\File;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Livewire\Attributes\Validate;
|
||||
|
||||
class Avatar extends Component
|
||||
{
|
||||
use WithFileUploads;
|
||||
|
||||
public $avatar;
|
||||
|
||||
public $x;
|
||||
public $y;
|
||||
public $width;
|
||||
public $height;
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.artist.avatar');
|
||||
}
|
||||
|
||||
public function save()
|
||||
{
|
||||
$disk = Storage::disk('static');
|
||||
$avatar = $this->avatar->store('avatars', 'static');
|
||||
|
||||
Image::load($disk->path($avatar))
|
||||
->manualCrop($this->width, $this->height, $this->x, $this->y)
|
||||
->save();
|
||||
ImageOptimizer::optimize($disk->path($avatar));
|
||||
auth()->user()->artists()->first()->update(compact('avatar'));
|
||||
$this->avatar = null;
|
||||
return redirect(request()->header('Referer'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user