Logo API
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
<?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('airlines', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('IATA_code', 3)->nullable();
|
||||
$table->string('ICAO_code', 4)->nullable();
|
||||
$table->string('name', 81)->nullable();
|
||||
$table->string('internal_name', 81)->nullable();
|
||||
$table->string('country_code', 2)->nullable();
|
||||
$table->string('country_name', 36)->nullable();
|
||||
$table->boolean('active');
|
||||
$table->string('logo', 40)->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('airlines');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class AirlinesSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$path = storage_path('app/private/seed_data/airlines.csv');
|
||||
$file = fopen($path, 'r');
|
||||
|
||||
$header = fgetcsv($file, separator: ';');
|
||||
|
||||
$keep = ['codeIataAirline', 'codeIcaoAirline', 'nameAirline', 'codeIso2Country', 'nameCountry', 'slug', 'statusAirline'];
|
||||
|
||||
$renames = [
|
||||
'airlineId' => 'id',
|
||||
'codeIataAirline' => 'IATA_code',
|
||||
'codeIcaoAirline' => 'ICAO_code',
|
||||
'slug' => 'internal_name',
|
||||
'nameAirline' => 'name',
|
||||
'codeIso2Country' => 'country_code',
|
||||
'nameCountry' => 'country_name',
|
||||
'statusAirline' => 'active'
|
||||
];
|
||||
|
||||
while (($row = fgetcsv($file, separator: ';')) !== false) {
|
||||
$data = array_combine($header, $row);
|
||||
$filtered = array_intersect_key($data, array_flip($keep));
|
||||
|
||||
foreach ($renames as $old => $new) {
|
||||
if (array_key_exists($old, $filtered)) {
|
||||
$filtered[$new] = $filtered[$old];
|
||||
unset($filtered[$old]);
|
||||
}
|
||||
}
|
||||
$filtered['active'] = $filtered['active'] === 'active';
|
||||
$filtered['logo'] = $filtered['IATA_code'] ? $filtered['IATA_code'].'.png' : null;
|
||||
DB::table('airlines')->insert($filtered);
|
||||
}
|
||||
|
||||
fclose($file);
|
||||
}
|
||||
}
|
||||
@@ -15,11 +15,6 @@ class DatabaseSeeder extends Seeder
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
// User::factory(10)->create();
|
||||
|
||||
User::factory()->create([
|
||||
'name' => 'Test User',
|
||||
'email' => 'test@example.com',
|
||||
]);
|
||||
$this->call(AirlinesSeeder::class);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user