Laravel spatie/laravel-permissions 问题(模型用户中的 HasRole )

发布于 2025-01-20 03:48:05 字数 391 浏览 6 评论 0原文

我的 spatie/laravel-permissions 库有问题。

以前我在我的系统中实现了它,但在进行作曲家更新后它停止工作......

问题是当我在我的用户模型中添加 HasRole 时。一切都崩溃了,我收到错误: “调用数组上的成员函数first()” 提到 PermissionRegistrar 包文件。

同样,如果我尝试在系统中输入另一条路线,出现的错误是“ 未定义的索引:名称”

表,并且按照文档执行了包安装过程,正如我之前所说,角色和权限系统之前对我有用。

应该注意的是,我已经创建了模型,在数据库中创建了 我应该提到的是,我之前用“描述”替换了“名称”字段,但我在库中遇到了一些配置问题,因此我运行了另一次迁移,添加了库所需的“名称”字段。运行迁移后,一切似乎都正常。正确工作

I have a problem with the spatie/laravel-permissions library.

Previously I had it implemented in my system but after doing composer update it stopped working...

The problem is when I add the HasRole in my User model. Everything crashes and I get the error:
"Call to a member function first() on array "
Making mention of the PermissionRegistrar package file.

Likewise, if I try to enter another route in my system, the error that appears is "
Undefined index: name"

It should be noted that I have my model created, my tables in the database and I carry out the package installation process following the documentation, and as I said before, the roles and permissions system worked for me before.

Something I should mention is that I had previously replaced the "name" field with "description" but I had some configuration problems with the library so I ran another migration adding the Name field, which the library requires. After running the migration, everything seemed to work correctly

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

病毒体 2025-01-27 03:48:05

您可能有一个与Spatie有关的缓存问题。如果您在播种DB时遇到任何类型的问题,则可以在Run()方法中添加此行的顶部

app()[\Spatie\Permission\PermissionRegistrar::class]->forgetCachedPermissions();

,如果您手动更改某些内容,请从数据库说,您可以尝试使用工匠命令

php artisan permission:cache-reset

https://spatie.be/docs/laravel-permission/v5/basic-usage/artisan#content-resetting-the-cache

请注意,即使您正在运行新的安装,也需要清除缓存通过使用

php artisan migrate:fresh --seed

You probably have a cache issue specifically related to Spatie. If you face any kind of issues when you are seeding your DB, you can add this line at the top of your seed within the run() method

app()[\Spatie\Permission\PermissionRegistrar::class]->forgetCachedPermissions();

On the other hand, if you changed something manually, let's say from DB, you can try with artisan command

php artisan permission:cache-reset

https://spatie.be/docs/laravel-permission/v5/basic-usage/artisan#content-resetting-the-cache

Note that you need to clear cache even if you are running a fresh install by using

php artisan migrate:fresh --seed
↙温凉少女 2025-01-27 03:48:05

那么您刚刚对所有软件包进行了完整更新?
这是一种可怕的情况,我认为我从未对所有软件包进行过完整更新。
我不确定您要使用或使用哪个版本的 spatie,这可能会有所帮助。

当我从 Laravel 5.7 到 Laravel 8 进行完整更新时,spatie 很痛苦。不只是一点点疼痛,而是4天的全力工作更新疼痛。所有数据库表都已重命名,并添加了更多表。然后我必须编写代码将 20k 用户和权限从旧表转移到具有正确关系的新表。然后我不得不去尝试并使用更新的功能......等等。恶梦。

正如您所看到的,您的问题对于正确答案有点模糊。

So you just ran a full update of all packages?
That is kind of a scary situation, I don't think I've ever done a full update to all packages.
I'm not sure what version of spatie you are coming or going with, that might help.

When I did a full update from Laravel 5.7 all the way to Laravel 8, spatie was a pain. Not just a little pain but a full on work for 4 days updating pain. All the database tables were renamed, more added. Then I had to write code to transfer 20k users and permissions over from the old tables to the new tables with correct relationships. Then I had to go though and use the newer functions...etc. Nightmare.

So as you can see you are a little vague in your question for a proper answer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文