mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-02 14:36:17 +00:00
Tags (#277)
This commit is contained in:
23
database/factories/TagFactory.php
Normal file
23
database/factories/TagFactory.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Tag;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
class TagFactory extends Factory
|
||||
{
|
||||
protected $model = Tag::class;
|
||||
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'project_id' => 1,
|
||||
'created_at' => Carbon::now(), //
|
||||
'updated_at' => Carbon::now(),
|
||||
'name' => $this->faker->randomElement(['production', 'staging', 'development']),
|
||||
'color' => $this->faker->randomElement(config('core.tag_colors')),
|
||||
];
|
||||
}
|
||||
}
|
24
database/migrations/2024_08_09_180021_create_tags_table.php
Normal file
24
database/migrations/2024_08_09_180021_create_tags_table.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('tags', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('project_id');
|
||||
$table->string('name');
|
||||
$table->string('color');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('tags');
|
||||
}
|
||||
};
|
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('taggables', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('tag_id');
|
||||
$table->unsignedBigInteger('taggable_id');
|
||||
$table->string('taggable_type');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('taggables');
|
||||
}
|
||||
};
|
@ -8,9 +8,12 @@
|
||||
use App\Models\Site;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
|
||||
class DatabaseSeeder extends Seeder
|
||||
{
|
||||
use WithFaker;
|
||||
|
||||
/**
|
||||
* Seed the application's database.
|
||||
*/
|
||||
@ -20,6 +23,12 @@ public function run(): void
|
||||
'name' => 'Test User',
|
||||
'email' => 'user@example.com',
|
||||
]);
|
||||
|
||||
$this->createResources($user);
|
||||
}
|
||||
|
||||
private function createResources(User $user): void
|
||||
{
|
||||
$server = Server::factory()->create([
|
||||
'user_id' => $user->id,
|
||||
'project_id' => $user->currentProject->id,
|
||||
|
Reference in New Issue
Block a user