ramiawadallah / boomveltest
Laravel 多认证包
Requires (Dev)
- fzaninotto/faker: ^1.9@dev
- illuminate/support: ^5.8@dev
- mockery/mockery: ^1.0@dev
- orchestra/database: ^3.8@dev
- orchestra/testbench: ^3.8@dev
- phpunit/phpunit: ^7.4@dev
This package is auto-updated.
Last update: 2024-09-06 09:33:00 UTC
README
composer require ramiawadallah/boomveltest Before proceeding : you can make a normal auth, check [this doc](https://github.com/bitfumes/laravel-multiauth#another-auth) Publish Migrations ```bash php artisan vendor:publish --tag="multiauth:migrations"
运行 迁移脚本 以在数据库中创建表格。
php artisan migrate
注意事项
如果你已经在管理员迁移中添加了新列,那么你需要通过上述命令生成第一个超级管理员。
php artisan vendor:publish --tag="multiauth:factories"
第一个管理员
显然,第一次你需要至少一个超级管理员来登录并创建其他管理员。
php artisan multiauth:seed --role=super
现在你可以通过访问 https://:8000/admin 使用 邮箱 = super@admin.com 和 密码 = secret 的凭证来登录你的管理员界面。显然,你稍后可以更改这些信息。
注册新管理员
要注册新用户,你需要访问 https://:8000/admin/register。
请注意,只有超级管理员可以创建新的管理员。
更改管理员视图
你可以发布包视图文件和覆盖你的文件,以便你拥有适合你项目设计的视图。
php artisan vendor:publish --tag="multiauth:views"
验证
是的,你可以通过发布配置文件来编写新列的验证规则或更改现有的验证规则。
php artisan vendor:publish --tag="multiauth:config"
更改前缀
你可以更改你刚刚发布的配置文件中的前缀。我们所说的前缀是指你想叫你的管理端的名字,我们称之为admin,你可以叫它任何你想的名字。假设你已将前缀更改为'master',现在在所有地方都将'admin'这个词更改为'master'。
/* |-------------------------------------------------------------------------- | Prefix |-------------------------------------------------------------------------- | | Use prefix to before the routes of multiauth package. | This way you can keep your admin page secure. | Default : admin */ 'prefix' => 'admin', // can change it to, lets say 'prefix' => 'master'
登录后重定向
你可以更改管理员部分的登录后重定向路径。只需在config/multiauth.php文件上更改此设置即可。
/* |-------------------------------------------------------------------------- | Redirect After Login |-------------------------------------------------------------------------- | | It will redirect to a path defined here after login. | You can change it to where ever you want to | redirect the admin after login. | Default : /admin/home */ 'redirect_after_login' => '/admin/home',
创建角色
要创建新角色,你有两种选择
- 使用 artisan 命令
php artisan multiauth:role rolename
- 使用界面。只需访问 https://:8000/admin/role。
现在你可以点击“添加角色”按钮来创建新角色。
编辑或删除角色也可以通过相同的界面完成
发布路由文件
php artisan vendor:publish --tag="multiauth:routes"
访问级别
使用中间件
- 你可以使用 'role' 中间件来允许不同管理员根据其角色访问特定部分。
Route::get('admin/check',function(){ return "This route can only be accessed by admin with role of Editor" })->middleware('role:editor');
这里你给出角色为大写、小写或混合写法都没有关系,这个包会处理所有这些。
- 如果你想让一个部分仅由超级用户访问,则使用 role:super 中间件。超级管理员可以访问所有低级角色的部分。
Route::get('admin/check',function(){ return "This route can only be accessed by super admin" })->middleware('role:super');
使用 Blade 语法
你可以简单地使用 blade 语法来显示或隐藏具有特定角色的管理员的部分。例如,如果你想为具有编辑角色的管理员显示一个按钮,则可以编写。
@admin('editor') <button>Only For Editor</button> @endadmin
如果你想添加多个角色,可以这样做
@admin('editor,publisher,any_role') <button> This is visible to admin with all these role</button> @endadmin
其他认证
除了管理员部分外,你还可以创建其他认证
php artisan multiauth:make {guard}
如果您想的话,也可以回滚这个授权。
php artisan multiauth:rollback {guard}
许可证
此包继承了其父框架Laravel的许可协议,因此是开源软件,在MIT许可证下授权。

