Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug} compatibily with Model::shouldBeStrict() #75

Merged
merged 2 commits into from
Mar 27, 2025

Conversation

gpibarra
Copy link
Contributor

@gpibarra gpibarra commented Mar 7, 2025

Install Laravel

mkdir -p /path/to/project/laravel
cd /path/to/project/laravel

composer create-project laravel/laravel .

php artisan migrate

composer require livewire/livewire filament/filament

# install admin panel
php artisan filament:install --panels

# create test user (admin)
php artisan make:filament-user --name=Admin [email protected] --password=Password123!

# test site
php artisan serve

Go to: http://127.0.0.1:8000/admin

Install Plugin

composer require joaopaulolndev/filament-edit-profile

Configure Plugin

app/Providers/Filament/AdminPanelProvider.php

<?php

// ...
+use Filament\Navigation\MenuItem;
+use Joaopaulolndev\FilamentEditProfile\FilamentEditProfilePlugin;
+use Joaopaulolndev\FilamentEditProfile\Pages\EditProfilePage;

class AdminPanelProvider extends PanelProvider
{
    public function panel(Panel $panel): Panel
    {
        return $panel
            // ...
+            ->userMenuItems([
+                'profile' => MenuItem::make()
+                    ->label(fn () => auth()->user()->name)
+                    ->url(fn (): string => EditProfilePage::getUrl())
+                    ->icon('heroicon-m-user-circle'),
+            ])
+            ->plugins([
+                FilamentEditProfilePlugin::make()
+                    ->slug('profile')
+                    ->shouldRegisterNavigation(false)
+                    ->shouldShowDeleteAccountForm(false)
+                    ->shouldShowSanctumTokens(false)
+                    ->shouldShowBrowserSessionsForm()
+                    ->shouldShowAvatarForm(false),
+            ])
            // ...
    }
}

Important

Notice: ->shouldShowAvatarForm(false)

Test Plugin

php artisan serve

Go to: http://127.0.0.1:8000/admin/profile

Change setup Models

./app/Providers/AppServiceProvider.php

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
+ use Illuminate\Database\Eloquent\Model;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     */
    public function register(): void
    {
        //
    }

    /**
     * Bootstrap any application services.
     */
    public function boot(): void
    {
+         Model::shouldBeStrict();
+         // Model::unguard();
    }
}

Go to: http://127.0.0.1:8000/admin/profile

Error

It doesn't work, the site throws the exception.

[previous exception] [object] (Illuminate\\Database\\Eloquent\\MissingAttributeException(code: 0): The attribute [avatar_url] either does not exist or was not retrieved for model [App\\Models\\User]. at ./laravel/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php:506)
[stacktrace]
#0 ./laravel/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php(486): Illuminate\\Database\\Eloquent\\Model->throwMissingAttributeExceptionIfApplicable()
#1 ./laravel/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php(1984): Illuminate\\Database\\Eloquent\\Model->getAttribute()
#2 ./laravel/vendor/joaopaulolndev/filament-edit-profile/src/Livewire/EditProfileForm.php(31): Illuminate\\Database\\Eloquent\\Model->only()

@gpibarra
Copy link
Contributor Author

@joaopaulolndev have you seen this PR?

@joaopaulolndev joaopaulolndev merged commit cb01eac into joaopaulolndev:main Mar 27, 2025
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants