fix: adding ability to update artist bg
This commit is contained in:
@@ -36,6 +36,10 @@ class Avatar extends Component
|
||||
Image::load($disk->path($avatar))
|
||||
->manualCrop($this->width, $this->height, $this->x, $this->y)
|
||||
->save();
|
||||
Image::load($disk->path($avatar))
|
||||
->width(350)
|
||||
->height(350)
|
||||
->save();
|
||||
ImageOptimizer::optimize($disk->path($avatar));
|
||||
auth()->user()->artists()->first()->update(compact('avatar'));
|
||||
$this->avatar = null;
|
||||
|
||||
48
site/app/Livewire/Artist/Header.php
Normal file
48
site/app/Livewire/Artist/Header.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?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 Header extends Component
|
||||
{
|
||||
use WithFileUploads;
|
||||
|
||||
public $header;
|
||||
|
||||
public $x;
|
||||
public $y;
|
||||
public $width;
|
||||
public $height;
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.artist.header');
|
||||
}
|
||||
|
||||
public function save()
|
||||
{
|
||||
$disk = Storage::disk('static');
|
||||
$header = $this->header->store('artist_headers', 'static');
|
||||
|
||||
Image::load($disk->path($header))
|
||||
->manualCrop($this->width, $this->height, $this->x, $this->y)
|
||||
->save();
|
||||
Image::load($disk->path($header))
|
||||
->width(270)
|
||||
->height(185)
|
||||
->save();
|
||||
ImageOptimizer::optimize($disk->path($header));
|
||||
auth()->user()->artists()->first()->update(compact('header'));
|
||||
$this->header = null;
|
||||
return redirect(request()->header('Referer'));
|
||||
}
|
||||
}
|
||||
@@ -64,9 +64,17 @@ class Artist extends Model
|
||||
public function avatar()
|
||||
{
|
||||
if (!$this->avatar) {
|
||||
return config('app.static_asset_url') . '/' . ('avatars/default_avatar_male.svg');
|
||||
return config('app.static_asset_url') . '/avatars/default_avatar_male.svg';
|
||||
}
|
||||
return config('app.static_asset_url') . '/' . $this->avatar;
|
||||
}
|
||||
|
||||
public function header()
|
||||
{
|
||||
if (!$this->header) {
|
||||
return config('app.static_asset_url') . '/artist_headers/default_artist_banner.png';
|
||||
}
|
||||
return config('app.static_asset_url') . '/' . $this->header;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user