Nexialist
Nexialist

Reputation: 1

Laraves Filament Railway Deploy 403 error

I am working with Laravel and Filament, and I deployed my project on Railway. The problem is that I get a 403 status when I try to log in; it redirects me to 403. I checked the Filament documentation and found this: https://filamentphp.com/docs/3.x/panels/installation#allowing-users-to-access-a-panel But when I implement it in my code, it throws an error: "Method 'App\Models\User::canAccessPanel()' is not compatible with method 'Filament\Models\Contracts\FilamentUser::canAccessPanel()'." Attached is an image of the error as well. Thanks for the help!

I can access to /admin panel, just /admin/login panelvscode User.php error

Upvotes: 0

Views: 748

Answers (3)

Lajos Arpad
Lajos Arpad

Reputation: 77045

Look at the example code they have given:

<?php
 
namespace App\Models;
 
use Filament\Models\Contracts\FilamentUser;
use Filament\Panel;
use Illuminate\Foundation\Auth\User as Authenticatable;
 
class User extends Authenticatable implements FilamentUser
{
    // ...
 
    public function canAccessPanel(Panel $panel): bool
    {
        return str_ends_with($this->email, '@yourdomain.com') && $this->hasVerifiedEmail();
    }
}

This method expects a Filament\Panel input which therefore needs to be used and returns a bool. So you need

use Filament\Panel;

Note that the error message did not complain about unknown Panel, so it's possible that you have another Panel class from another namespace, in which case you can do

use Filament\Panel FilamentPanel;

and then have FilamentPanel $panel in the method declaration.

Upvotes: 1

Karim Elsherbiny
Karim Elsherbiny

Reputation: 7

[![enter image description here][1]][1]

Add This part in your User class [1]: https://i.sstatic.net/iVJSZa2j.png

Upvotes: -2

ggonzal
ggonzal

Reputation: 147

You need to include "Filament/Panel" before the class:

use Filament\Panel;

Upvotes: 1

Related Questions