在 Cpanel 中部署 Laravel 应用程序后,如何创建第一个具有创建较少用户权限的管理员用户?
如果我的 Laravel 应用程序具有基于角色的权限,其中只有一种类型的用户(超级管理员)能够注册用户,我将如何创建该初始用户?
我应该使用播种机并从那里创建用户吗?密码是否会在代码中公开(可能来自环境变量?)?
或者我可以从命令行创建它吗?
If my Laravel app has role-based permissions where only a type of user (superadmin) has the ability to register users, how would I create that initial user?
Should I use a seeder and create the user from there? Would the password be exposed in the code (from env variable maybe?)?
Or could I create it from the command line?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
就我个人而言,我不喜欢将临时用户存储在 .env 文件中或(上帝禁止)直接存储在 Seeder 中。
我有一个从命令行运行的标准问题用户创建 Artisan 命令。请注意,我还在用户模型上使用了默认情况下对
password
进行哈希处理的变元(请参见答案底部)。App\Models\User
然后您可以从命令行运行:
并从那里创建您的初始(或任何后续)管理员。
Personally, I don't like to have temporary users stored in the .env files or (god forbid) directly in the Seeder.
I have a standard issue user-creation Artisan command that I run from the command line. Note that I also use a mutator on the User model which hashes
password
by default (see bottom of answer).App\Models\User
Then you can just run:
from your command line and create your initial (or any subsequent) admins from there.
播种是方法。对于密码,只需按照 Laravel 基础框架的相同方式对其进行哈希处理即可。
当然,密码对于那些有权访问您的源代码的人来说是可见的。当您的网站首次启动并运行时更改密码。
Seeding is the way. For the password just Hash it in the same way the laravel base framework does it.
Of course, the password will be visible to those with access to your source code. Change the password when your site is up and running the first time.