list trips

add, remove flights
This commit is contained in:
Richard Morgan
2017-05-14 20:57:30 -04:00
parent 37d345840b
commit 09fa83af8b
16 changed files with 426 additions and 4 deletions

View File

@@ -0,0 +1,24 @@
<?php
/*
|--------------------------------------------------------------------------
| Model Factories
|--------------------------------------------------------------------------
|
| Here you may define all of your model factories. Model factories give
| you a convenient way to create models for testing and seeding your
| database. Just tell the factory how a default model should look.
|
*/
$factory->define(App\Libraries\Trips\Models\Trips::class, function (Faker\Generator $faker) {
return [
'name' => $faker->text(10),
];
});
$factory->define(App\Libraries\Trips\Models\Flights::class, function (Faker\Generator $faker) {
return [
'destination' => $faker->countryISOAlpha3, //TODO change this
];
});

0
database/migrations/.gitkeep Normal file → Executable file
View File

View File

@@ -0,0 +1,58 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class Trips extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('trips', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->timestamps();
});
Schema::create('flights', function (Blueprint $table) {
$table->increments('id');
$table->string('destination');
$table->timestamps();
});
Schema::create('trip_flights', function (Blueprint $table) {
$table->increments('id');
$table->integer('trips_id')->unsigned();
$table->integer('flights_id')->unsigned();
$table->timestamps();
$table->unique(['trips_id', 'flights_id']);
$table->foreign('trips_id')->references('id')->on('trips');
});
Schema::create('airports', function (Blueprint $table) {
$table->increments('id');
$table->string('name', 256);
$table->string('code', 3);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('trip_flights');
Schema::drop('trips');
Schema::drop('flights');
Schema::drop('airports');
}
}

11
database/seeds/DatabaseSeeder.php Normal file → Executable file
View File

@@ -12,5 +12,16 @@ class DatabaseSeeder extends Seeder
public function run()
{
// $this->call('UsersTableSeeder');
factory(App\Libraries\Trips\Models\Trips::class, 5)
->create()
->each(function ($trip) {
$flights = factory(App\Libraries\Trips\Models\Flights::class, 2)
->create()
->each(function ($flight) use ($trip) {
$trip->flights()->attach($flight->id);
});
});
}
}

21
database/seeds/TripsSeeder.php Executable file
View File

@@ -0,0 +1,21 @@
<?php
use Illuminate\Database\Seeder;
class TripsSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
dd('here');
factory(App\Libraries\Trips\Models\Trips::class, 5)
->create()
->each(function ($trip) {
$trip->flights->save(factory(App\Libraries\Trips\Models\Flights::class, 2)->make());
});
}
}