feature - 8 - Add development seeder
This commit is contained in:
parent
f226295d72
commit
8336df4551
2 changed files with 81 additions and 0 deletions
|
|
@ -101,6 +101,10 @@ echo "Waiting for database..."
|
|||
sleep 5
|
||||
php artisan migrate --force || echo "Migration failed or not needed"
|
||||
|
||||
# Run development seeder (only in dev environment)
|
||||
echo "Running development seeder..."
|
||||
php artisan db:seed --class=DevelopmentSeeder --force || echo "Seeding skipped or already done"
|
||||
|
||||
# Generate app key if not set
|
||||
if [ -z "$APP_KEY" ] || [ "$APP_KEY" = "base64:YOUR_KEY_HERE" ]; then
|
||||
echo "Generating application key..."
|
||||
|
|
|
|||
77
database/seeders/DevelopmentSeeder.php
Normal file
77
database/seeders/DevelopmentSeeder.php
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Dish;
|
||||
use App\Models\Planner;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
class DevelopmentSeeder extends Seeder
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
// Create main planner
|
||||
$planner = Planner::factory()->create([
|
||||
'name' => 'Development Planner',
|
||||
'email' => 'myrmidex@myrmidex.net',
|
||||
'password' => Hash::make('Password'),
|
||||
]);
|
||||
|
||||
// Create a few users
|
||||
$users = [
|
||||
User::factory()->create([
|
||||
'planner_id' => $planner->id,
|
||||
'name' => 'Alice Johnson',
|
||||
'email' => 'alice@example.com',
|
||||
'password' => Hash::make('Password'),
|
||||
]),
|
||||
User::factory()->create([
|
||||
'planner_id' => $planner->id,
|
||||
'name' => 'Bob Smith',
|
||||
'email' => 'bob@example.com',
|
||||
'password' => Hash::make('Password'),
|
||||
]),
|
||||
User::factory()->create([
|
||||
'planner_id' => $planner->id,
|
||||
'name' => 'Charlie Brown',
|
||||
'email' => 'charlie@example.com',
|
||||
'password' => Hash::make('Password'),
|
||||
]),
|
||||
];
|
||||
|
||||
// Create various dishes
|
||||
$dishNames = [
|
||||
'Spaghetti Bolognese',
|
||||
'Chicken Curry',
|
||||
'Caesar Salad',
|
||||
'Beef Stir Fry',
|
||||
'Vegetable Lasagne',
|
||||
'Fish Tacos',
|
||||
'Mushroom Risotto',
|
||||
'BBQ Ribs',
|
||||
'Greek Salad',
|
||||
'Pad Thai',
|
||||
'Margherita Pizza',
|
||||
'Beef Burger',
|
||||
'Chicken Fajitas',
|
||||
'Vegetable Soup',
|
||||
'Salmon Teriyaki',
|
||||
];
|
||||
|
||||
foreach ($dishNames as $dishName) {
|
||||
$dish = Dish::factory()->create([
|
||||
'planner_id' => $planner->id,
|
||||
'name' => $dishName,
|
||||
]);
|
||||
|
||||
// Randomly assign dish to 1-3 users
|
||||
$assignedUsers = $users->random(rand(1, 3));
|
||||
$dish->users()->attach($assignedUsers->pluck('id'));
|
||||
}
|
||||
|
||||
$this->command->info('Development data seeded successfully!');
|
||||
$this->command->info('Login credentials: myrmidex@myrmidex.net / Password');
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue