Featured tours working

This commit is contained in:
2025-09-15 13:40:20 +10:00
parent f0e7ce30fc
commit e965cc2780
24 changed files with 384 additions and 26 deletions

View File

@@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('continents', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('internal_name')->unique();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('continents');
}
};

View File

@@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('countries', function (Blueprint $table) {
$table->id();
$table->string('internal_name')->unique();
$table->string('name');
$table->string('country_code', 2)->unique();
$table->foreignId('continent_id')
->constrained('continents')
->onDelete('restrict'); // or ->onDelete('cascade') if you prefer
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('countries');
}
};

View File

@@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('tours', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('internal_name');
$table->string('short_description');
$table->integer('length');
$table->integer('price');
$table->string('level');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('tours');
}
};

View File

@@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('tour_countries', function (Blueprint $table) {
$table->id();
$table->foreignId('country_id')->constrained();
$table->foreignId('tour_id')->constrained();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('tour_countries');
}
};

View File

@@ -0,0 +1,24 @@
<?php
namespace Database\Seeders;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
class ContinentSeeder extends Seeder
{
public function run(): void
{
DB::table('continents')->insert([
['id' => 1, 'name' => 'Australia & Oceania', 'internal_name' => 'oceania'],
['id' => 2, 'name' => 'Africa', 'internal_name' => 'africa'],
['id' => 3, 'name' => 'Asia', 'internal_name' => 'asia'],
['id' => 4, 'name' => 'Europe', 'internal_name' => 'europe'],
['id' => 5, 'name' => 'North America', 'internal_name' => 'north_america'],
['id' => 6, 'name' => 'South America', 'internal_name' => 'south_america'],
['id' => 7, 'name' => 'Antarctica', 'internal_name' => 'antarctica'],
]);
}
}

View File

@@ -0,0 +1,29 @@
<?php
namespace Database\Seeders;
use App\Models\Continent;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
class CountrySeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
$map = Continent::all()->pluck('id', 'internal_name')->toArray();
\DB::table('countries')->insert([
['internal_name'=>'comoros','name'=>'Comoros','country_code'=>'km','continent_id'=>$map['africa']],
['internal_name'=>'madagascar','name'=>'Madagascar','country_code'=>'mg','continent_id'=>$map['africa']],
['internal_name'=>'suriname','name'=>'Suriname','country_code'=>'sn','continent_id'=>$map['south_america']],
['internal_name'=>'mauritania','name'=>'Mauritania','country_code'=>'mr','continent_id'=>$map['africa']],
['internal_name'=>'china','name'=>'China','country_code'=>'cn','continent_id'=>$map['asia']],
['internal_name'=>'tajikistan','name'=>'Tajikistan','country_code'=>'tj','continent_id'=>$map['asia']],
['internal_name'=>'gabon','name'=>'Gabon','country_code'=>'ga','continent_id'=>$map['africa']],
]);
}
}

View File

@@ -14,9 +14,12 @@ class DatabaseSeeder extends Seeder
public function run(): void
{
// User::factory(10)->create();
$this->call(ContinentSeeder::class);
$this->call(CountrySeeder::class);
$this
->call(ContinentSeeder::class)
->call(CountrySeeder::class)
->call(TourSeeder::class)
->call(TourCountrySeeder::class)
;
User::factory()->create([
'name' => 'Test User',

View File

@@ -0,0 +1,27 @@
<?php
namespace Database\Seeders;
use App\Models\Country;
use App\Models\Tour;
use App\Models\TourCountry;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
class TourCountrySeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
$tourMap = Tour::all()->pluck('id', 'internal_name')->toArray();
$countryMap= Country::all()->pluck('id', 'internal_name')->toArray();
\DB::table('tour_countries')->insert([
['tour_id' => $tourMap['cantonese_charm'], 'country_id' => $countryMap['china']],
['tour_id' => $tourMap['fujianese_fantasy'], 'country_id' => $countryMap['china']],
['tour_id' => $tourMap['hebei_hijinx'], 'country_id' => $countryMap['china']],
]);
}
}

View File

@@ -0,0 +1,23 @@
<?php
namespace Database\Seeders;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
class TourSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
\DB::table('tours')->insert([
['length' => 8, 'name' => "Cantonese Charm", 'short_description' => "Guangdong is known for it's big, global cities, but there is so much more to discover and pristine natural beauty.", 'internal_name' => "cantonese_charm", 'level' => "Beginner", 'price' => 1000],
['length' => 7, 'name' => "Fujianese Fantasy", 'short_description' => "Experience fresh seafood in Xiamen, and then move rurally for an authentic dive into Hakka culture", 'internal_name' => "fujianese_fantasy", 'level' => "Beginner", 'price' => 1200],
['length' => 10, 'name' => "Hebei Hijinx", 'short_description' => "The Great Wall, Great Food and ancient treasures in one of China's most underrated provinces.", 'internal_name' => "hebei_hijinx", 'level' => "Moderate", 'price' => 1500],
]);
}
}