mirror of
https://github.com/NyaaStudios/nyaabooru.git
synced 2025-12-10 05:42:58 +00:00
71 lines
1.2 KiB
PHP
71 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Pages;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Validation\Rule;
|
|
use Livewire\Attributes\Validate;
|
|
use Livewire\Component;
|
|
use Livewire\WithFileUploads;
|
|
|
|
class Profile extends Component
|
|
{
|
|
use WithFileUploads;
|
|
|
|
public User $user;
|
|
|
|
public $avatar = null;
|
|
public string $name = '';
|
|
|
|
public function mount(User $user)
|
|
{
|
|
$this->user = $user;
|
|
$this->name = $user->name;
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.pages.profile')->title($this->user->name);
|
|
}
|
|
|
|
public function rules()
|
|
{
|
|
return [
|
|
'avatar' => [
|
|
'nullable',
|
|
'image',
|
|
'max:10240',
|
|
],
|
|
'name' => [
|
|
'required',
|
|
'string',
|
|
'min:2',
|
|
'max:40',
|
|
Rule::unique('users', 'name')->ignore($this->user),
|
|
],
|
|
];
|
|
}
|
|
|
|
public function updated($name, $value)
|
|
{
|
|
if (Auth::id() != $this->user->id)
|
|
{
|
|
abort(401);
|
|
}
|
|
|
|
$this->validate();
|
|
|
|
$this->user->update([ $name => $value ]);
|
|
|
|
if (isset($this->avatar))
|
|
{
|
|
$this->user->avatarExt = $this->avatar->getClientOriginalExtension();
|
|
$this->user->save();
|
|
|
|
$this->avatar->storeAs('avatars', $this->user->id);
|
|
return $this->redirect("/profiles/{$this->user->id}");
|
|
}
|
|
|
|
}
|
|
}
|