0

I am just new in Laravel 6. I installed the default auth in Laravel. I want to have multiple user.

  1. Admin - This user can monitor everything from the dashboard and other pages.
  2. Maker - This user can create only a job.
  3. Approver - This user can only approve the job but it can't create job.
  4. Viewer - This user can only view all the pages of the application.

Other this I need to auto generate an OPGROUP ID for each companies. And I want to the user who is logged in only see what are the data that is save under their account.

Can you help me to achieve my goal please.

kdb.mjb
  • 1
  • 1

1 Answers1

0

We have to follow the below steps

First, we have to create a table by using the below command in which we will store the roles

php artisan make: migration create_admins_table --create=admins

after creating the migration, we will add the columns

$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->rememberToken(); // I put this linke incase if it was missing

then we will run the migration

php artisan migrate

then we will run the below command

php artisan make: model Admin 

do not forget to add the below code in the admin.php model if there aren't

protected $guard = 'admin';
protected $fillable = [
        'name', 'email', 'password',
    ];

we have to set up our guard in the config/auth.php file right after the guards, we should add the below code

'admin' => [
            'driver' => 'session',
            'provider' => 'admins',
        ],
'admin-api' => [
                'driver' => 'token',
                'provider' => 'admins',
            ],

right after the provider, we should add the below code

'admins' => [
            'driver' => 'eloquent',
            'model' => App\Admin::class,
        ],

let's create controller

php artisan make: controller AdminController

let's create a view called admin and route in the web.php

Route::get()'/admin',AdminController@index)

and add the below code in the admin controller

public function __construct()
            {
                $this->middleware('auth:admin');
            }

You can insert user roles in the table (Admin, Maker, Approver, Viewer) and direct it to views that you want

OmarSafi
  • 178
  • 1
  • 10
  • Thank you. Follow up question. I am planning to create only 1view on each role. But hide the features or button depend on the role of the user. Is that possible? – kdb.mjb Mar 16 '20 at 06:22