138 lines
4.7 KiB
PHP
138 lines
4.7 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace Modules\Customer\Database\Seeders;
|
||
|
|
|
||
|
|
use Illuminate\Database\Seeder;
|
||
|
|
use Illuminate\Support\Facades\DB;
|
||
|
|
use Illuminate\Support\Facades\Hash;
|
||
|
|
use Illuminate\Support\Str;
|
||
|
|
use Modules\Booking\Database\Seeders\BookingTableSeeder;
|
||
|
|
use Modules\Restaurant\Models\Customer;
|
||
|
|
use Spatie\Permission\Models\Permission;
|
||
|
|
use Spatie\Permission\Models\Role;
|
||
|
|
|
||
|
|
class CustomerDatabaseSeeder extends Seeder
|
||
|
|
{
|
||
|
|
private $customerPermissions = [
|
||
|
|
'dashboard',
|
||
|
|
'customer',
|
||
|
|
'profile_index',
|
||
|
|
'profile_edit',
|
||
|
|
'menu_types_index',
|
||
|
|
'menu_sections_index',
|
||
|
|
'menu_categories_index',
|
||
|
|
'food_categories_index',
|
||
|
|
'food_items_index',
|
||
|
|
'food_variants_index',
|
||
|
|
'food_variant_ingredients_index',
|
||
|
|
'tables_index',
|
||
|
|
'reservations_index',
|
||
|
|
'reservations_create',
|
||
|
|
'reservation_unavailability_index',
|
||
|
|
'my_orders_index',
|
||
|
|
'my_orders_create',
|
||
|
|
'my_orders_edit',
|
||
|
|
'my_orders_delete',
|
||
|
|
'my_orders_show',
|
||
|
|
];
|
||
|
|
|
||
|
|
public function run(): void
|
||
|
|
{
|
||
|
|
/** ----------------------------------------------------------------
|
||
|
|
* 1) Create Permissions for Customer Guard
|
||
|
|
* ----------------------------------------------------------------*/
|
||
|
|
foreach ($this->customerPermissions as $permissionName) {
|
||
|
|
Permission::updateOrCreate([
|
||
|
|
'name' => $permissionName,
|
||
|
|
'guard_name' => 'customer',
|
||
|
|
]);
|
||
|
|
}
|
||
|
|
|
||
|
|
/** ----------------------------------------------------------------
|
||
|
|
* 2) Create Customer Role
|
||
|
|
* ----------------------------------------------------------------*/
|
||
|
|
$customerRole = Role::updateOrCreate([
|
||
|
|
'name' => 'Customer',
|
||
|
|
'guard_name' => 'customer',
|
||
|
|
'restaurant_id' => null,
|
||
|
|
]);
|
||
|
|
|
||
|
|
$customerRole->syncPermissions($this->customerPermissions);
|
||
|
|
|
||
|
|
/** ----------------------------------------------------------------
|
||
|
|
* 3) Walk-in Customer
|
||
|
|
* ----------------------------------------------------------------*/
|
||
|
|
Customer::updateOrCreate([
|
||
|
|
'customer_code' => 'CUST-WALKIN',
|
||
|
|
], [
|
||
|
|
'restaurant_id' => 1,
|
||
|
|
'name' => 'Walk-in',
|
||
|
|
'phone' => '00123456789',
|
||
|
|
'address' => 'Counter',
|
||
|
|
'status' => 1,
|
||
|
|
]);
|
||
|
|
|
||
|
|
/** ----------------------------------------------------------------
|
||
|
|
* 4) Demo Customers
|
||
|
|
* ----------------------------------------------------------------*/
|
||
|
|
for ($i = 1; $i <= 10; $i++) {
|
||
|
|
$customer = Customer::updateOrCreate(
|
||
|
|
['email' => "customer{$i}@example.com"],
|
||
|
|
[
|
||
|
|
'restaurant_id' => 1,
|
||
|
|
'customer_code' => 'CUST-'.strtoupper(Str::random(6)),
|
||
|
|
'name' => "Customer {$i}",
|
||
|
|
'email_verified_at' => now(),
|
||
|
|
'phone' => "013000000{$i}",
|
||
|
|
'password' => Hash::make('password123'),
|
||
|
|
'platform' => 'WEB',
|
||
|
|
'address' => 'Dhaka, Bangladesh',
|
||
|
|
'status' => 1,
|
||
|
|
]
|
||
|
|
);
|
||
|
|
|
||
|
|
// Assign role safely
|
||
|
|
$customer->assignRole($customerRole); // ✅ pass name only
|
||
|
|
}
|
||
|
|
|
||
|
|
$this->command->info('✅ Seeded 1 Walk-in + 10 demo customers successfully.');
|
||
|
|
|
||
|
|
/** ----------------------------------------------------------------
|
||
|
|
* 5) OAuth Clients for Users and Customers
|
||
|
|
* ----------------------------------------------------------------*/
|
||
|
|
$this->createOAuthClient('users', 'User Personal Access Client');
|
||
|
|
$this->createOAuthClient('customers', 'Customer Personal Access Client');
|
||
|
|
|
||
|
|
// 6) Booking Module Seeders
|
||
|
|
$this->call([
|
||
|
|
BookingTableSeeder::class,
|
||
|
|
]);
|
||
|
|
}
|
||
|
|
|
||
|
|
private function createOAuthClient(string $provider, string $name): void
|
||
|
|
{
|
||
|
|
$clientId = (string) Str::uuid();
|
||
|
|
$clientSecret = Str::random(40);
|
||
|
|
|
||
|
|
DB::table('oauth_clients')->updateOrInsert(
|
||
|
|
['provider' => $provider],
|
||
|
|
[
|
||
|
|
'id' => $clientId,
|
||
|
|
'owner_type' => null,
|
||
|
|
'owner_id' => null,
|
||
|
|
'name' => $name,
|
||
|
|
'secret' => Hash::make($clientSecret),
|
||
|
|
'provider' => $provider,
|
||
|
|
'redirect_uris' => '[]',
|
||
|
|
'grant_types' => '["personal_access"]',
|
||
|
|
'revoked' => 0,
|
||
|
|
'created_at' => now(),
|
||
|
|
'updated_at' => now(),
|
||
|
|
]
|
||
|
|
);
|
||
|
|
|
||
|
|
$this->command->info("🔐 OAuth $provider Client ID: $clientId");
|
||
|
|
$this->command->info("🔐 OAuth $provider Secret: $clientSecret");
|
||
|
|
}
|
||
|
|
}
|