Skip to content

[Bug]:Custom Profile Page not working when registered in Panel Provider #7

@swarakaka

Description

@swarakaka

Description

Description

I am trying to implement a custom profile page in my Laravilt project. I have created a custom page class that extends Laravilt\Auth\Pages\Profile and registered it in my Panel Provider using the profile() method. However, the custom profile page is not being loaded or is not functioning as expected.

AdminPanelProvider.php

->profile(CustomProfilePage::class)

CustomProfilePage.php

<?php

namespace App\Pages;


use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Validator;
use Laravilt\Auth\Pages\Profile;
use Laravilt\Forms\Components\TextInput;

class CustomProfilePage extends Profile
{
    public function updateProfile(array $data): mixed
    {
        $panel = $this->getPanel();
        $guard = $panel->getAuthGuard();
        $user = Auth::guard($guard)->user();

        // Validate the data
        $validator = Validator::make($data, [
            'username' => ['required', 'string', 'max:255'],
            'email' => ['required', 'email', 'max:255', 'unique:users,email,'.$user->id],
        ]);

        if ($validator->fails()) {
            return back()->withErrors($validator)->withInput();
        }

        $validated = $validator->validated();

        // Update user
        $user->update($validated);

        notify(__('laravilt-auth::auth.profile.page.profile_updated'));

        return back();
    }

    protected function getSchema(): array
    {
        $panel = $this->getPanel();
        $guard = $panel->getAuthGuard();
        $user = Auth::guard($guard)->user();

        return [
            TextInput::make('username')
                ->label(__('Username'))
                ->default($user->username ?? '')
                ->required()
                ->tabindex(1),

            TextInput::make('email')
                ->label(__('laravilt-auth::auth.fields.email'))
                ->email()
                ->default($user->email ?? '')
                ->required()
                ->tabindex(2),
        ];
    }

    protected function getInertiaProps(): array
    {
        $panel = $this->getPanel();
        $guard = $panel->getAuthGuard();
        $user = Auth::guard($guard)->user();

        return [
            'user' => $user,
            'status' => session('status'),
        ];
    }
}

Steps to Reproduce

Expected Behavior

Actual Behavior

Package Version

1.0.3

PHP Version

8.4

Laravel Version

12

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions