Skip to content

mohitmehta1996/laravel-user-types

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

Laravel User types - Admin/User

This package create user types like Simple user, Admin and Super Admin.

Installation

You can install the package via composer:

composer require mohit/usertype
php artisan vendor:publish --provider="mohit\usertype\UsertypeProvider"
php artisan migrate

Create Admin User

php artisan create:admin

It will ask you to enter name, email and password. Then you can login with entered email and password.

Create Super Admin User

Super Admin user have roles of accessing admin pages as well as user pages.

php artisan create:super

It will ask you to enter name, email and password. Then you can login with entered email and password.

Usage

This package creates and registeres new middleware which you can use in routes file. You can assign middleware to either group of routes or individual routes.

For admin,

Route::group(['middleware' => 'authorize:admin'], function(){
    //
});

For user,

Route::group(['middleware' => 'authorize:user'], function(){
    //
});

For super admin,

Route::group(['middleware' => 'authorize:admin|user'], function(){
    //
});

Using In Blades

@if(auth()->user()->type == 'admin')
  //
@endif

Styling Unauthorized page

When any user try to access page for which he is not authorized then it will redirect him to unauthorized page. This page follow bootstrap structure. You can style this page by creating new css file under 'public/css/unauthorized.css'.