D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
forge
/
ghanempharmacy.com
/
database
/
seeders
/
Filename :
LocationSeeder.php
back
Copy
<?php namespace Database\Seeders; use App\Models\DeliveryArea; use App\Models\DeliveryCity; use App\Models\DeliveryCountryCode; use App\Models\DeliveryState; use Illuminate\Database\Seeder; class LocationSeeder extends Seeder { /** * Run the database seeds. * * @return void */ public function run() { // 1. Ensure Country Exists (Egypt) $country = DeliveryCountryCode::firstOrCreate( ['country_code' => 'EG'], ['shipping_cost' => 0] ); $states = [ 'Cairo' => [ 'Nasr City' => ['The 10th District', 'The 7th District', 'Abbas El Akkad'], 'Maadi' => ['Degla', 'El Sarayat', 'New Maadi'], 'Heliopolis' => ['Korba', 'Roxy', 'Sheraton'], ], 'Giza' => [ '6th of October' => ['District 1', 'District 2', 'Al Motamayez'], 'Sheikh Zayed' => ['District 1', 'District 10', 'Beverly Hills'], 'Dokki' => ['Messaha', 'Shooting Club'], ], 'Alexandria' => [ 'Sidi Gaber' => ['Smouha', 'Sporting'], 'Montaza' => ['Maamoura', 'Mandara'], ] ]; foreach ($states as $stateName => $cities) { // 2. Create State $state = DeliveryState::firstOrCreate( [ 'country_id' => $country->id, 'name' => $stateName ], [ 'cost' => 50, // Default shipping cost 'status' => 1 ] ); foreach ($cities as $cityName => $areas) { // 3. Create City $city = DeliveryCity::firstOrCreate( [ 'state_id' => $state->id, 'name' => $cityName ], [ 'cost' => 20, // Additional cost for city 'status' => 1 ] ); foreach ($areas as $areaName) { // 4. Create Area DeliveryArea::firstOrCreate( [ 'city_id' => $city->id, 'name' => $areaName ], [ 'cost' => 10, // Additional cost for area 'status' => 1 ] ); } } } } }