majebry/laravel6-userable
Composer 安装命令:
composer require majebry/laravel6-userable
包简介
Multiple User Type Models for Laravel 6
README 文档
README
This package transforms Laravel's User model to be an "abstract-like" model so that you can create as much separate userable (user-type) models as you wish with their auth controllers and a middleware by just running some command.
Installation
Use composer dependency manager to install this package.
composer require majebry/laravel6-userable
Usage
- publish migrations:
php artisan vendor:publish --provider="Majebry\LaravelUserable\UserableServiceProvider" --tag="migrations"
- Include Userable trait into your Laravel's User model
class User extends Authenticatable { use \Majebry\LaravelUserable\Traits\Userable; //... }
So, anytime you want to call user info for any userable model you can do Model::find($id)->userable
- Now, for example, if we want to generate a user-type called
Customer, we run the following command
php artsian userable:make Customer
This command will generate a Customer model under app directory
and a x_create_customers_table.php under database\migrations directory
You can add the fields that you wish to that migration before running it
- In app/Http/Kernal.php, register the following middleware
protected $routeMiddleware = [ // ... 'userable-auth' => \Majebry\LaravelUserable\Http\Middleware\UserTypeMiddleware::class, ];
Now for example, if you want to protect a route to be only accessible for StoreAdmin, you can chain the Route with ->middleware('userable-auth:store-admin')
Contributing
...
Todo
- Probably make the generator command also generates custom authentication actions(routes and controllers), middleware and/or views with the generator command.
- Add tests
- Making the UserTypeMiddleware supports multiple user-types
- Hooking into on User/Userable
Deleteevent?
License
统计信息
- 总下载量: 49
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 10
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-12-15