refactor: update user default role

pull/17/head
Saiful Alam 2 years ago
parent f4c80a7797
commit c6795b0123

@ -54,5 +54,5 @@ MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
SANCTUM_STATEFUL_DOMAINS="localhost,localhost:3000,localhost:8000,127.0.0.1,127.0.0.1:8000,::1"
DEFAULT_ROLE_ID=2
DEFAULT_ROLE_SLUG=user
DELETE_PREVIOUS_ACCESS_TOKENS_ON_LOGIN=false

@ -45,10 +45,11 @@ class UserController extends Controller {
'name' => $creds['name']
]);
UserRole::create([
'user_id' => $user->id,
'role_id' => config('hydra.default_user_role_id', 2)
]);
$user->roles()->attach(Role::firstOrCreate([
'slug' => config('hydra.default_user_role_slug', 'user')
],[
'name' => Str::title(config('hydra.default_user_role_slug', 'user'))
]));
return $user;

@ -22,11 +22,11 @@ return [
| This value is the default user role id that will be assigned to new users
| when they register.
|
| 1 = Admin role, 2 = User role, 3 = Customer Role - Check RoleSeeder for more
| admin = Admin role, user = User role, customer = Customer Role - Check RoleSeeder for more
|
*/
'default_user_role_id' => env('DEFAULT_ROLE_ID', 2),
'default_user_role_slug' => env('DEFAULT_ROLE_SLUG', 'admin'),
/*
|--------------------------------------------------------------------------

@ -21,9 +21,8 @@ class DatabaseSeeder extends Seeder
// 'email' => 'test@example.com',
// ]);
$this->call([
UsersSeeder::class,
RoleSeeder::class,
UserRoleSeeder::class
UsersSeeder::class,
]);
}

@ -1,33 +0,0 @@
<?php
namespace Database\Seeders;
use App\Models\UserRole;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
class UserRoleSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Schema::disableForeignKeyConstraints();
DB::table('user_roles')->truncate();
Schema::enableForeignKeyConstraints();
UserRole::create([
'user_id'=>1,
'role_id'=>1
]); //admin
UserRole::create([
'user_id'=>1,
'role_id'=>5
]);//all
}
}

@ -2,12 +2,14 @@
namespace Database\Seeders;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use App\Models\Role
use App\Models\User;
use Illuminate\Support\Str;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
class UsersSeeder extends Seeder
{
@ -22,10 +24,15 @@ class UsersSeeder extends Seeder
DB::table('users')->truncate();
Schema::enableForeignKeyConstraints();
User::create([
$user = User::create([
'email'=>'admin@hydra.project',
'password'=>Hash::make('hydra'),
'name'=>'Hydra Admin'
]);
$user->roles()->attach(Role::firstOrCreate([
'slug' => config('hydra.default_user_role_slug', 'user')
],[
'name' => Str::title(config('hydra.default_user_role_slug', 'user'))
]));
}
}

Loading…
Cancel
Save