list trips
add, remove flights
This commit is contained in:
24
database/factories/TripsFactory.php
Normal file
24
database/factories/TripsFactory.php
Normal 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
0
database/migrations/.gitkeep
Normal file → Executable file
58
database/migrations/2017_05_14_152748_trips.php
Executable file
58
database/migrations/2017_05_14_152748_trips.php
Executable 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
11
database/seeds/DatabaseSeeder.php
Normal file → Executable 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
21
database/seeds/TripsSeeder.php
Executable 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());
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user