简体   繁体   English

Laravel 5.1 Entrust-设置第一角色/权限

[英]Laravel 5.1 Entrust - Setting up first roles/permissions

I installed entrust on my laravel 5.1. 我在laravel 5.1上安装了委托。 I'm wondering what's the best way to create your first roles? 我想知道创建第一个角色的最佳方法是什么?

I see some people creating them with routes but this doesn't seem like a clean way to me. 我看到有人用路线创建路线,但这对我来说似乎不是一种干净的方法。 Should I just seed my first roles directly into my database or is there a better way? 我应该只将我的第一个角色直接播种到数据库中,还是有更好的方法?

In my opinion, this is up to personal preference. 我认为,这取决于个人喜好。 As you mentioned already, using a database seeder is a perfectly reasonable solution. 就像您已经提到的那样,使用数据库播种器是一个非常合理的解决方案。

If you really want to contain and separate the code that initializes the roles/permissions, or anything else you need in your application, you can also opt to create a custom Artisan command within Laravel that does the initial setup tasks you need to do. 如果您确实想包含和分隔用于初始化角色/权限或应用程序中所需其他任何内容的代码,则还可以选择在Laravel中创建一个自定义Artisan命令,以执行所需的初始设置任务。 With this method, you can separate your initial production set-up and you can still utilize your database seeders without having to modify them for testing purposes. 使用这种方法,您可以分离最初的生产设置,并且仍然可以使用数据库播种器,而无需出于测试目的而对其进行修改。

Resources: 资源:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM