Init(Core): add project to git and add seeders and factory

This commit is contained in:
2026-04-28 21:29:43 +03:30
commit 15bd23cdd2
101 changed files with 12093 additions and 0 deletions

1
database/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
*.sqlite*

View File

@@ -0,0 +1,24 @@
<?php
namespace Database\Factories;
use App\Models\Content;
use App\Models\Page;
use Illuminate\Database\Eloquent\Factories\Factory;
class ContentFactory extends Factory
{
protected $model = Content::class;
public function definition(): array
{
$type = fake()->randomElement(['text', 'image', 'video']);
return [
'page_id' => Page::factory(),
'type' => $type,
'body' => $type === 'text' ? fake()->paragraph() : fake()->imageUrl(),
'title' => fake()->optional()->sentence(),
];
}
}

View File

@@ -0,0 +1,22 @@
<?php
namespace Database\Factories;
use App\Models\Image;
use App\Models\Page;
use Illuminate\Database\Eloquent\Factories\Factory;
class ImageFactory extends Factory
{
protected $model = Image::class;
public function definition(): array
{
return [
'path' => fake()->imageUrl(640, 480),
'user_id' => fake()->numberBetween(1, 10),
'page_id' => Page::factory(),
'user_token' => fake()->uuid(),
];
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace Database\Factories;
use App\Models\Page;
use Illuminate\Database\Eloquent\Factories\Factory;
class PageFactory extends Factory
{
protected $model = Page::class;
public function definition(): array
{
return [
'user_token' => fake()->uuid(),
'url' => fake()->url(),
];
}
}

View File

@@ -0,0 +1,28 @@
<?php
namespace Database\Factories;
use App\Models\Post;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
class PostFactory extends Factory
{
protected $model = Post::class;
public function definition(): array
{
$title = fake()->sentence();
return [
'title' => $title,
'description' => fake()->optional()->text(200),
'content' => fake()->paragraphs(5, true),
'slug' => Str::slug($title),
'image_path' => fake()->imageUrl(800, 600, 'posts'),
'image_thumbnail' => fake()->imageUrl(200, 200, 'posts'),
'image_alt' => fake()->sentence(),
'user_token' => fake()->uuid(),
];
}
}

View File

@@ -0,0 +1,38 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\User>
*/
class UserFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return [
'name' => fake()->name(),
'email' => fake()->unique()->safeEmail(),
'email_verified_at' => now(),
'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
'remember_token' => Str::random(10),
];
}
/**
* Indicate that the model's email address should be unverified.
*/
public function unverified(): static
{
return $this->state(fn (array $attributes) => [
'email_verified_at' => null,
]);
}
}

View File

@@ -0,0 +1,31 @@
<?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('pages', function (Blueprint $table) {
$table->id();
$table->string('user_token');
$table->string('url');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('pages');
}
};

View File

@@ -0,0 +1,33 @@
<?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('contents', function (Blueprint $table) {
$table->id();
$table->foreignId('page_id')->constrained('pages')->onDelete('cascade');
$table->enum('type', ['text', 'image', 'video']);
$table->string('body');
$table->string('title')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('contents');
}
};

View File

@@ -0,0 +1,41 @@
<?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('posts', function (Blueprint $table) {
$table->id();
$table->string('title');
$table->string('description')->nullable();
$table->text('content');
$table->string('slug');
$table->string('image_path');
$table->string('image_thumbnail');
$table->string('image_alt');
$table->string('user_token');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('posts');
}
};

View File

@@ -0,0 +1,33 @@
<?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('images', function (Blueprint $table) {
$table->id();
$table->string('path');
$table->foreignId('user_id');
$table->foreignId('page_id')->constrained('pages')->onDelete('cascade');
$table->string('user_token');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('images');
}
};

View File

@@ -0,0 +1,21 @@
<?php
namespace Database\Seeders;
use App\Models\Content;
use App\Models\Page;
use Illuminate\Database\Seeder;
class ContentSeeder extends Seeder
{
public function run(): void
{
$pages = Page::all();
foreach ($pages as $page) {
Content::factory()->count(rand(3, 8))->create([
'page_id' => $page->id,
]);
}
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
{
/**
* Seed the application's database.
*/
public function run(): void
{
$this->call([
PageSeeder::class,
ContentSeeder::class,
PostSeeder::class,
ImageSeeder::class,
]);
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace Database\Seeders;
use App\Models\Image;
use App\Models\Page;
use Illuminate\Database\Seeder;
class ImageSeeder extends Seeder
{
public function run(): void
{
$pages = Page::all();
foreach ($pages as $page) {
Image::factory()->count(rand(2, 5))->create([
'page_id' => $page->id,
]);
}
}
}

View File

@@ -0,0 +1,14 @@
<?php
namespace Database\Seeders;
use App\Models\Page;
use Illuminate\Database\Seeder;
class PageSeeder extends Seeder
{
public function run(): void
{
Page::factory()->count(10)->create();
}
}

View File

@@ -0,0 +1,14 @@
<?php
namespace Database\Seeders;
use App\Models\Post;
use Illuminate\Database\Seeder;
class PostSeeder extends Seeder
{
public function run(): void
{
Post::factory()->count(20)->create();
}
}