Skip to content

majebry/laravel6-userable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Laravel Userable

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

  1. publish migrations:
php artisan vendor:publish --provider="Majebry\LaravelUserable\UserableServiceProvider" --tag="migrations"
  1. 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

  1. 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

  1. 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 Delete event?

License

MIT

About

Generates multiple user-types in a polymorphic relation with Laravel's User model

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages