Inserito le role e utenti demo nel seeder
This commit is contained in:
@@ -1,29 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreatePermissionsTable extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
$permissionsTable = config('acl.tables.permissions', 'permissions');
|
||||
Schema::create($permissionsTable, function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->string('name');
|
||||
$table->string('guard_name');
|
||||
$table->text('description')->nullable();
|
||||
$table->softDeletes();
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['name', 'guard_name']);
|
||||
});
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
$tables = config('acl.tables');
|
||||
Schema::dropIfExists($tables['permissions']);
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateGroupsTable extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
$groupsTable = config('acl.tables.groups', 'groups');
|
||||
$teams = config('acl.teams');
|
||||
$columnNames = config('acl.column_names');
|
||||
|
||||
Schema::create($groupsTable, function (Blueprint $table) use ($teams, $columnNames) {
|
||||
$table->bigIncrements('id');
|
||||
|
||||
if ($teams || config("acl.testing")) {
|
||||
$table->unsignedBigInteger($columnNames['team_foreign_key'])->nullable();
|
||||
$table->index($columnNames['team_foreign_key'], 'groups_team_foreign_key_index');
|
||||
}
|
||||
|
||||
$table->string('name');
|
||||
$table->string('guard_name');
|
||||
$table->text('description')->nullable();
|
||||
$table->softDeletes();
|
||||
$table->timestamps();
|
||||
|
||||
if ($teams || config('acl.testing')) {
|
||||
$table->unique([$columnNames['team_foreign_key'], 'name', 'guard_name']);
|
||||
} else {
|
||||
$table->unique(['name', 'guard_name']);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
$groupsTable = config('acl.tables.groups', 'groups');
|
||||
Schema::dropIfExists($groupsTable);
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Junges\ACL\AclRegistrar;
|
||||
|
||||
class CreateModelHasPermissionsTable extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
$columnNames = config('acl.column_names');
|
||||
|
||||
$modelHasPermissions = config('acl.tables.model_has_permissions', 'model_has_permissions');
|
||||
$permissionsTable = config('acl.tables.permissions', 'permissions');
|
||||
$teams = config('acl.teams');
|
||||
|
||||
Schema::create($modelHasPermissions, function (Blueprint $table) use ($permissionsTable, $columnNames, $teams) {
|
||||
$table->unsignedBigInteger(AclRegistrar::$pivotPermission);
|
||||
$table->string('model_type');
|
||||
$table->unsignedBigInteger($columnNames['model_morph_key']);
|
||||
$table->index([$columnNames['model_morph_key'], 'model_type'], 'model_has_permissions_id_model_type_index');
|
||||
|
||||
$table->foreign(AclRegistrar::$pivotPermission)
|
||||
->references('id')
|
||||
->on($permissionsTable)
|
||||
->cascadeOnDelete();
|
||||
|
||||
if ($teams) {
|
||||
$table->unsignedBigInteger($columnNames['team_foreign_key']);
|
||||
$table->index($columnNames['team_foreign_key'], 'model_has_permissions_team_foreign_key_index');
|
||||
|
||||
$table->primary([$columnNames['team_foreign_key'], AclRegistrar::$pivotPermission, $columnNames['model_morph_key'], 'model_type'],
|
||||
'model_has_permissions_permission_model_type_primary');
|
||||
} else {
|
||||
$table->primary([AclRegistrar::$pivotPermission, $columnNames['model_morph_key'], 'model_type'],
|
||||
'model_has_permissions_permission_model_type_primary');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
$modelHasPermissionTable = config('acl.tables.model_has_permissions', 'model_has_permissions');
|
||||
Schema::dropIfExists($modelHasPermissionTable);
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Junges\ACL\AclRegistrar;
|
||||
|
||||
class CreateModelHasGroupsTable extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
$columnNames = config('acl.column_names');
|
||||
$modelHasGroups = config('acl.tables.model_has_groups', 'model_has_groups');
|
||||
$groupsTable = config('acl.tables.groups', 'groups');
|
||||
$teams = config('acl.teams');
|
||||
|
||||
Schema::create($modelHasGroups, function (Blueprint $table) use ($groupsTable, $columnNames, $teams) {
|
||||
$table->unsignedBigInteger(AclRegistrar::$pivotGroup);
|
||||
|
||||
$table->string('model_type');
|
||||
$table->unsignedBigInteger($columnNames['model_morph_key']);
|
||||
$table->index([$columnNames['model_morph_key'], 'model_type'], 'model_has_groups_model_id_model_type_index');
|
||||
|
||||
$table->foreign(AclRegistrar::$pivotGroup)
|
||||
->references('id')
|
||||
->on($groupsTable)
|
||||
->cascadeOnDelete();
|
||||
|
||||
if ($teams) {
|
||||
$table->unsignedBigInteger($columnNames['team_foreign_key']);
|
||||
$table->index($columnNames['team_foreign_key'], 'model_has_groups_team_foreign_key_index');
|
||||
|
||||
$table->primary([$columnNames['team_foreign_key'], AclRegistrar::$pivotGroup, $columnNames['model_morph_key'], 'model_type'],
|
||||
'model_has_groups_group_model_type_primary');
|
||||
} else {
|
||||
$table->primary([AclRegistrar::$pivotGroup, $columnNames['model_morph_key'], 'model_type'],
|
||||
'model_has_groups_group_model_type_primary');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
$modelHasGroupsTable = config('acl.tables.model_has_groups', 'model_has_groups');
|
||||
Schema::dropIfExists($modelHasGroupsTable);
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Junges\ACL\AclRegistrar;
|
||||
|
||||
class CreateGroupHasPermissionsTable extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
$groupHasPermissionTable = config('acl.tables.group_has_permissions', 'group_has_permissions');
|
||||
$groupsTable = config('acl.tables.groups', 'groups');
|
||||
$permissionsTable = config('acl.tables.permissions', 'permissions');
|
||||
|
||||
Schema::create($groupHasPermissionTable, function (Blueprint $table) use ($groupsTable, $permissionsTable) {
|
||||
$table->unsignedBigInteger(AclRegistrar::$pivotPermission);
|
||||
$table->unsignedBigInteger(AclRegistrar::$pivotGroup);
|
||||
|
||||
$table->foreign(AclRegistrar::$pivotPermission)
|
||||
->references('id')
|
||||
->on($permissionsTable)
|
||||
->cascadeOnDelete();
|
||||
|
||||
$table->foreign(AclRegistrar::$pivotGroup)
|
||||
->references('id')
|
||||
->on($groupsTable)
|
||||
->cascadeOnDelete();
|
||||
|
||||
$table->primary([AclRegistrar::$pivotPermission, AclRegistrar::$pivotGroup], 'group_has_permission_permission_id_group_id_primary');
|
||||
});
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
$groupHasPermissionsTable = config('acl.tables.group_has_permissions', 'group_has_permissions');
|
||||
|
||||
Schema::dropIfExists($groupHasPermissionsTable);
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class ColumnUsersRoles extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
//
|
||||
$table->softDeletes();
|
||||
$table->string('user_role',25)->default('user')->nullable(false);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
//
|
||||
$table->dropColumn('user_role');
|
||||
$table->dropSoftDeletes();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ class DatabaseSeeder extends Seeder
|
||||
UserSeeder::class,
|
||||
TagSeeder::class,
|
||||
CategorieSeeder::class,
|
||||
RoleSeeder::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
83
database/seeders/RoleSeeder.php
Normal file
83
database/seeders/RoleSeeder.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Spatie\Permission\Models\Permission;
|
||||
use Spatie\Permission\Models\Role;
|
||||
use Spatie\Permission\PermissionRegistrar;
|
||||
|
||||
class RoleSeeder extends Seeder
|
||||
{
|
||||
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
// Role Creation
|
||||
$role_admin = Role::create([
|
||||
'name' => 'admin'
|
||||
]);
|
||||
$role_user = Role::create([
|
||||
'name' => 'user'
|
||||
]);
|
||||
$role_guest = Role::create([
|
||||
'name' => 'guest'
|
||||
]);
|
||||
|
||||
// Permission Creation
|
||||
Permission::create([
|
||||
'name' => 'conti'
|
||||
]);
|
||||
Permission::create([
|
||||
'name' => 'consumi'
|
||||
]);
|
||||
Permission::create([
|
||||
'name' => 'automobili'
|
||||
]);
|
||||
Permission::create([
|
||||
'name' => 'contatti'
|
||||
]);
|
||||
Permission::create([
|
||||
'name' => 'affitti'
|
||||
]);
|
||||
Permission::create([
|
||||
'name' => 'progetti'
|
||||
]);
|
||||
Permission::create([
|
||||
'name' => 'amministrazione'
|
||||
]);
|
||||
|
||||
// Assegnazione permessi al ruolo user
|
||||
$role_user->givePermissionTo('affitti');
|
||||
$role_user->givePermissionTo('automobili');
|
||||
$role_user->givePermissionTo('contatti');
|
||||
$role_user->givePermissionTo('consumi');
|
||||
$role_user->givePermissionTo('conti');
|
||||
$role_user->givePermissionTo('progetti');
|
||||
// Assegnazione permessi al ruolo guest
|
||||
$role_guest->givePermissionTo('affitti');
|
||||
|
||||
$admin = User::create([
|
||||
'name'=>'Amministratore',
|
||||
'email'=>'admin@localhost.local',
|
||||
'password'=>Hash::make('password'),
|
||||
])->assignRole($role_admin);
|
||||
|
||||
$user = User::create([
|
||||
'name'=>'Utente',
|
||||
'email'=>'user@localhost.local',
|
||||
'password'=>Hash::make('password'),
|
||||
])->assignRole($role_user);
|
||||
|
||||
$guest = User::create([
|
||||
'name'=>'Guest',
|
||||
'email'=>'guest@localhost.local',
|
||||
'password'=>Hash::make('password'),
|
||||
])->assignRole($role_guest);
|
||||
}
|
||||
}
|
||||
@@ -22,16 +22,9 @@ class UserSeeder extends Seeder
|
||||
'name'=>'SystemUser',
|
||||
'email'=>'system@localhost.local',
|
||||
'password'=>Hash::make(Str::random(16)),
|
||||
'user_role'=>'user',
|
||||
]
|
||||
);
|
||||
DB::table('users')->insert(
|
||||
[
|
||||
'name'=>'admin',
|
||||
'email'=>env('SYSADMIN_MAIL'),
|
||||
'password'=>Hash::make('admin'),
|
||||
'user_role'=>'admin',
|
||||
|
||||
]
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user