base commit
This commit is contained in:
29
database/seeders/AdminUserSeeder.php
Normal file
29
database/seeders/AdminUserSeeder.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Department;
|
||||
use App\Models\User;
|
||||
use BezhanSalleh\FilamentShield\Support\Utils;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
class AdminUserSeeder extends Seeder
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
$admin = User::query()->updateOrCreate(
|
||||
['email' => 'admin@company.com'],
|
||||
[
|
||||
'name' => 'Admin',
|
||||
'password' => Hash::make('password'),
|
||||
'email_verified_at' => now(),
|
||||
'department_id' => Department::query()->where('code', 'ADM')->value('id'),
|
||||
],
|
||||
);
|
||||
|
||||
$admin->assignRole(Utils::getSuperAdminName());
|
||||
}
|
||||
}
|
||||
25
database/seeders/DatabaseSeeder.php
Normal file
25
database/seeders/DatabaseSeeder.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class DatabaseSeeder extends Seeder
|
||||
{
|
||||
use WithoutModelEvents;
|
||||
|
||||
public function run(): void
|
||||
{
|
||||
$this->call([
|
||||
DepartmentSeeder::class,
|
||||
PositionSeeder::class,
|
||||
ShiftSeeder::class,
|
||||
RoleSeeder::class,
|
||||
AdminUserSeeder::class,
|
||||
DemoDataSeeder::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
22
database/seeders/DemoDataSeeder.php
Normal file
22
database/seeders/DemoDataSeeder.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Employee;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class DemoDataSeeder extends Seeder
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
if (Employee::query()->exists()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Employee::factory()
|
||||
->count(25)
|
||||
->create();
|
||||
}
|
||||
}
|
||||
56
database/seeders/DepartmentSeeder.php
Normal file
56
database/seeders/DepartmentSeeder.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Department;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class DepartmentSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* @var array<string, array{name: string, code: string, description: string}>
|
||||
*/
|
||||
private const DEPARTMENTS = [
|
||||
'production' => [
|
||||
'name' => 'Production',
|
||||
'code' => 'PROD',
|
||||
'description' => 'Manufacturing and production operations.',
|
||||
],
|
||||
'warehouse' => [
|
||||
'name' => 'Warehouse',
|
||||
'code' => 'WH',
|
||||
'description' => 'Inventory and logistics.',
|
||||
],
|
||||
'administration' => [
|
||||
'name' => 'Administration',
|
||||
'code' => 'ADM',
|
||||
'description' => 'General administration and office management.',
|
||||
],
|
||||
'hr' => [
|
||||
'name' => 'HR',
|
||||
'code' => 'HR',
|
||||
'description' => 'Human resources and personnel management.',
|
||||
],
|
||||
'accounting' => [
|
||||
'name' => 'Accounting',
|
||||
'code' => 'ACC',
|
||||
'description' => 'Finance and accounting.',
|
||||
],
|
||||
];
|
||||
|
||||
public function run(): void
|
||||
{
|
||||
foreach (self::DEPARTMENTS as $department) {
|
||||
Department::query()->updateOrCreate(
|
||||
['code' => $department['code']],
|
||||
[
|
||||
'name' => $department['name'],
|
||||
'description' => $department['description'],
|
||||
'is_active' => true,
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
32
database/seeders/PositionSeeder.php
Normal file
32
database/seeders/PositionSeeder.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Position;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class PositionSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* @var list<string>
|
||||
*/
|
||||
private const POSITIONS = [
|
||||
'Operator',
|
||||
'Mechanic',
|
||||
'Electrician',
|
||||
'Cleaner',
|
||||
'Manager',
|
||||
];
|
||||
|
||||
public function run(): void
|
||||
{
|
||||
foreach (self::POSITIONS as $positionName) {
|
||||
Position::query()->firstOrCreate(
|
||||
['name' => $positionName],
|
||||
['description' => null],
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
51
database/seeders/RoleSeeder.php
Normal file
51
database/seeders/RoleSeeder.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\User;
|
||||
use BezhanSalleh\FilamentShield\Support\Utils;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Spatie\Permission\Models\Role;
|
||||
|
||||
class RoleSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* @var list<string>
|
||||
*/
|
||||
private const ROLES = [
|
||||
'administrator',
|
||||
'hr_manager',
|
||||
'supervisor',
|
||||
'department_manager',
|
||||
'viewer',
|
||||
];
|
||||
|
||||
public function run(): void
|
||||
{
|
||||
Utils::createRole();
|
||||
|
||||
$guardName = $this->guardName();
|
||||
|
||||
foreach (self::ROLES as $roleName) {
|
||||
Role::firstOrCreate([
|
||||
'name' => $roleName,
|
||||
'guard_name' => $guardName,
|
||||
]);
|
||||
}
|
||||
|
||||
$admin = User::query()->where('email', 'admin@company.com')->first();
|
||||
|
||||
if ($admin !== null) {
|
||||
$admin->assignRole(Utils::getSuperAdminName());
|
||||
}
|
||||
}
|
||||
|
||||
private function guardName(): string
|
||||
{
|
||||
$guard = Utils::getFilamentAuthGuard();
|
||||
|
||||
return $guard !== '' ? $guard : (string) config('auth.defaults.guard', 'web');
|
||||
}
|
||||
}
|
||||
53
database/seeders/ShiftSeeder.php
Normal file
53
database/seeders/ShiftSeeder.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Shift;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class ShiftSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* @var array<string, array{name: string, starts_at: string, ends_at: string}>
|
||||
*/
|
||||
private const SHIFTS = [
|
||||
'A' => [
|
||||
'name' => 'Shift A',
|
||||
'starts_at' => '06:00:00',
|
||||
'ends_at' => '14:00:00',
|
||||
],
|
||||
'B' => [
|
||||
'name' => 'Shift B',
|
||||
'starts_at' => '14:00:00',
|
||||
'ends_at' => '22:00:00',
|
||||
],
|
||||
'C' => [
|
||||
'name' => 'Shift C',
|
||||
'starts_at' => '22:00:00',
|
||||
'ends_at' => '06:00:00',
|
||||
],
|
||||
'Night' => [
|
||||
'name' => 'Night Shift',
|
||||
'starts_at' => '22:00:00',
|
||||
'ends_at' => '06:00:00',
|
||||
],
|
||||
];
|
||||
|
||||
public function run(): void
|
||||
{
|
||||
foreach (self::SHIFTS as $code => $shift) {
|
||||
Shift::query()->updateOrCreate(
|
||||
['code' => $code],
|
||||
[
|
||||
'name' => $shift['name'],
|
||||
'starts_at' => $shift['starts_at'],
|
||||
'ends_at' => $shift['ends_at'],
|
||||
'description' => null,
|
||||
'is_active' => true,
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user