user profile updates

This commit is contained in:
yuriko 🦊 2025-07-26 15:06:05 -04:00
parent c7c621b086
commit ea140671bc
9 changed files with 78 additions and 27 deletions

View file

@ -19,11 +19,15 @@ class AuthController extends Controller
$authUser = User::updateOrCreate(
[ 'email' => $user->getEmail() ],
[ 'name' => $user->getName() ]
);
if ($authUser)
{
if ($authUser->name == '')
{
$authUser->name = $user->getName();
$authUser->save();
}
Auth::login($authUser);
return redirect('/');
}

View file

@ -6,6 +6,8 @@ use Livewire\Component;
class Icon extends Component
{
public string $family = 'classic';
public string $variant = 'light';
public string $name = 'paw-simple';
public string $label = '';
public string $style = '';

View file

@ -4,6 +4,7 @@ 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;
@ -14,15 +15,39 @@ class Profile extends Component
public User $user;
#[Validate('image|max:10240')]
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 updated()
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)
{
@ -31,10 +56,16 @@ class Profile extends Component
$this->validate();
$this->user->avatarExt = $this->avatar->getClientOriginalExtension();
$this->user->save();
$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}");
}
$this->avatar->storeAs('avatars', $this->user->id);
return $this->redirect("/profiles/{$this->user->id}");
}
}