当我的“APP_ENV=local”更改为生产并使用 FilamentPHP 时,生产中出现错误 403

error 403 in production when my `APP_ENV=local` change to production and using FilamentPHP

提问人:Trance Code 提问时间:10/23/2023 更新时间:10/23/2023 访问量:50

问:

我在数字海洋中创建了一个液滴,并在从本地到生产的app_env中测试了我的项目,当我这样做时,我最终得到了一个 403 禁止错误,显然我不能将其留在本地,因为我最终会暴露我所有的 .env 配置,现在我按照将 FilamentUser 添加到用户模型和其他模型的步骤,在这些模型中我管理其他面板的单独用户......我还添加了公共函数canAccessPanel,但它一直返回错误403,您对可能出错的地方有什么建议或想法吗?,或者在哪里检查其他东西?

enter image description here

这是我在 User!


namespace App\Models;

// use Illuminate\Contracts\Auth\MustVerifyEmail;

use Filament\Models\Contracts\FilamentUser;
use Filament\Models\Contracts\HasTenants;
use Filament\Panel;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Collection;
use Laravel\Sanctum\HasApiTokens;

class User extends Authenticatable implements HasTenants, FilamentUser
{
    use HasApiTokens, HasFactory, Notifiable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array<int, string>
     */
    protected $fillable = [
        'name',
        'email',
        'password',
    ];

    /**
     * The attributes that should be hidden for serialization.
     *
     * @var array<int, string>
     */
    protected $hidden = [
        'password',
        'remember_token',
    ];

    /**
     * The attributes that should be cast.
     *
     * @var array<string, string>
     */
    protected $casts = [
        'email_verified_at' => 'datetime',
        'password' => 'hashed',
    ];

    //relacion de los usuarios con las empreas
    public function companies(): BelongsToMany
    {
        return $this->belongsToMany(Company::class);
    }

    public function canAccessTenant(Model $tenant): bool
    {
        //
        return $this->companies->contains($tenant);
    }

    public function getTenants(Panel $panel): array|Collection
    {
        //Empresas que va a gestionar o que tiene este usuario 
        return $this->companies;
    }

    public function canAccessPanel(Panel $panel): bool
    {
        return str_ends_with($this->email, '@yourdomain.com') && $this->hasVerifiedEmail();
    }
}```
php linux laravel filamentphp

评论

1赞 Vaibhavraj Roham 10/23/2023
这应该可以帮助您 filamentphp.com/community/danharrin-panel-403-in-production
0赞 AmooAti 10/24/2023
只需根据您的需要更改逻辑即可。如果您没有任何关于谁可以访问面板的具体规则,只需canAccessPanelreturn true;

答: 暂无答案