fix: adding user avatar editing
This commit is contained in:
@@ -31,6 +31,11 @@ class ArtistController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
public function avatar() {
|
||||
$user = auth()->user();
|
||||
return view('')
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
|
||||
@@ -18,6 +18,8 @@ class ProfileController extends Controller
|
||||
{
|
||||
return view('profile.edit', [
|
||||
'user' => $request->user(),
|
||||
'artist' => $request->user()->artists->first(),
|
||||
'avatar' => $request->user()->artists->first()->avatar,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
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'));
|
||||
}
|
||||
}
|
||||
@@ -61,4 +61,12 @@ class Artist extends Model
|
||||
return $this->hasMany(Wallet::class);
|
||||
}
|
||||
|
||||
public function avatar()
|
||||
{
|
||||
if (!$this->avatar) {
|
||||
return asset('resources/img/default_avatars/default_avatar_male.svg');
|
||||
}
|
||||
return config('app.static_asset_url') . '/' . $this->avatar;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user