TrackType feat: added hierarchy, seeders, factory and CRUD
This commit is contained in:
parent
f89f1a97ee
commit
6a595a60dd
6 changed files with 224 additions and 6 deletions
32
database/factories/TrackTypeFactory.php
Normal file
32
database/factories/TrackTypeFactory.php
Normal file
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\TrackType;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\TrackType>
|
||||
*/
|
||||
class TrackTypeFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'code' => $this->faker->unique()->text(16),
|
||||
'visibility' => $this->faker->randomElement([true, false]),
|
||||
'type_name' => Str::random(20),
|
||||
'description' => Str::random(255),
|
||||
'analyze_cue_points' => $this->faker->randomElement([true, false]),
|
||||
'parent_id' => function () {
|
||||
return TrackType::count() > 3 ? TrackType::where('id', '<=', 3)->random(1)->first()->id : null;
|
||||
}
|
||||
];
|
||||
}
|
||||
}
|
|
@ -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::table('cc_track_types', function (Blueprint $table) {
|
||||
$table->foreignId('parent_id')->after('id')->nullable()->references('id')->on('cc_track_types');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('cc_track_types', function (Blueprint $table) {
|
||||
$table->dropColumn('parent_id');
|
||||
});
|
||||
}
|
||||
};
|
|
@ -12,11 +12,8 @@ class DatabaseSeeder extends Seeder
|
|||
*/
|
||||
public function run(): void
|
||||
{
|
||||
// \App\Models\User::factory(10)->create();
|
||||
|
||||
// \App\Models\User::factory()->create([
|
||||
// 'name' => 'Test User',
|
||||
// 'email' => 'test@example.com',
|
||||
// ]);
|
||||
$this->call([
|
||||
TrackTypeSeeder::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
45
database/seeders/TrackTypeSeeder.php
Normal file
45
database/seeders/TrackTypeSeeder.php
Normal file
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class TrackTypeSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
DB::table('cc_track_types')->insert([
|
||||
'code' => 'MUSICA',
|
||||
'visibility' => false,
|
||||
'type_name' => 'Musica',
|
||||
'description' => 'Tracce musicali',
|
||||
'analyze_cue_points' => false,
|
||||
'parent_id' => null,
|
||||
]);
|
||||
|
||||
DB::table('cc_track_types')->insert([
|
||||
'code' => 'JINGLES',
|
||||
'visibility' => false,
|
||||
'type_name' => 'Jingles',
|
||||
'description' => 'Tracce jingle',
|
||||
'analyze_cue_points' => false,
|
||||
'parent_id' => null,
|
||||
]);
|
||||
|
||||
|
||||
|
||||
DB::table('cc_track_types')->insert([
|
||||
'code' => 'SPOT',
|
||||
'visibility' => false,
|
||||
'type_name' => 'Spot',
|
||||
'description' => 'Tracce pubblicitarie',
|
||||
'analyze_cue_points' => false,
|
||||
'parent_id' => null,
|
||||
]);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue