composed project, added packages, models, controllers, seeders, mirgations etc.
This commit is contained in:
56
database/factories/EventFactory.php
Normal file
56
database/factories/EventFactory.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Event;
|
||||
use App\Services\Faker\Image\{Contracts\ProviderInterface, FakerImageProvider, ImageStorage};
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Support\Str;
|
||||
use Random\RandomException;
|
||||
|
||||
/**
|
||||
* @extends Factory<Event>
|
||||
*/
|
||||
class EventFactory extends Factory
|
||||
{
|
||||
private const int NB_WORDS = 5;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
* @throws RandomException
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
static $venuesCount = config('common.seeding.model.venue.count');
|
||||
static $counter = 1;
|
||||
static $imageProvider = app(FakerImageProvider::class)->use(config('image.faker.provider.loremflickr.type'))
|
||||
->apply();
|
||||
|
||||
$image = new ImageStorage(
|
||||
config('image.storage.poster'),
|
||||
random_int(400, 1280),
|
||||
random_int(400, 960),
|
||||
ProviderInterface::KEYWORDS
|
||||
);
|
||||
|
||||
$poster = $imageProvider->getImage($image);
|
||||
|
||||
// Note: numberBetween method is unsafe if you need all `venues`.`id` values be used for constraining ¯\_(ツ)_/¯
|
||||
$venuesId = $counter > $venuesCount ? $this->faker->numberBetween(1, $venuesCount) : $counter++;
|
||||
|
||||
return [
|
||||
'venue_id' => $venuesId,
|
||||
'name' => Str::of($this->faker->sentence(self::NB_WORDS))->rtrim('.'),
|
||||
'event_date' => $this->faker->unique()->dateTimeBetween(
|
||||
'-3 months',
|
||||
'3 months',
|
||||
env('APP_TIMEZONE', 'UTC')
|
||||
),
|
||||
'poster' => $poster,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,7 @@ class UserFactory extends Factory
|
||||
'name' => fake()->name(),
|
||||
'email' => fake()->unique()->safeEmail(),
|
||||
'email_verified_at' => now(),
|
||||
'password' => static::$password ??= Hash::make('password'),
|
||||
'password' => static::$password ??= Hash::make('What_the_heck?'),
|
||||
'remember_token' => Str::random(10),
|
||||
];
|
||||
}
|
||||
|
||||
27
database/factories/VenueFactory.php
Normal file
27
database/factories/VenueFactory.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Venue;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends Factory<Venue>
|
||||
*/
|
||||
class VenueFactory extends Factory
|
||||
{
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'name' => $this->faker->catchPhrase,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ return new class extends Migration
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('users', function (Blueprint $table) {
|
||||
Schema::create('users', static function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name');
|
||||
$table->string('email')->unique();
|
||||
@@ -21,13 +21,13 @@ return new class extends Migration
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
Schema::create('password_reset_tokens', function (Blueprint $table) {
|
||||
Schema::create('password_reset_tokens', static function (Blueprint $table) {
|
||||
$table->string('email')->primary();
|
||||
$table->string('token');
|
||||
$table->timestamp('created_at')->nullable();
|
||||
});
|
||||
|
||||
Schema::create('sessions', function (Blueprint $table) {
|
||||
Schema::create('sessions', static function (Blueprint $table) {
|
||||
$table->string('id')->primary();
|
||||
$table->foreignId('user_id')->nullable()->index();
|
||||
$table->string('ip_address', 45)->nullable();
|
||||
|
||||
@@ -11,13 +11,13 @@ return new class extends Migration
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('cache', function (Blueprint $table) {
|
||||
Schema::create('cache', static function (Blueprint $table) {
|
||||
$table->string('key')->primary();
|
||||
$table->mediumText('value');
|
||||
$table->integer('expiration');
|
||||
});
|
||||
|
||||
Schema::create('cache_locks', function (Blueprint $table) {
|
||||
Schema::create('cache_locks', static function (Blueprint $table) {
|
||||
$table->string('key')->primary();
|
||||
$table->string('owner');
|
||||
$table->integer('expiration');
|
||||
|
||||
@@ -11,7 +11,7 @@ return new class extends Migration
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('jobs', function (Blueprint $table) {
|
||||
Schema::create('jobs', static function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('queue')->index();
|
||||
$table->longText('payload');
|
||||
@@ -21,7 +21,7 @@ return new class extends Migration
|
||||
$table->unsignedInteger('created_at');
|
||||
});
|
||||
|
||||
Schema::create('job_batches', function (Blueprint $table) {
|
||||
Schema::create('job_batches', static function (Blueprint $table) {
|
||||
$table->string('id')->primary();
|
||||
$table->string('name');
|
||||
$table->integer('total_jobs');
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
<?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('venues', static function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name', 255)->unique();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('venues');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,30 @@
|
||||
<?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('events', static function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('venue_id')->nullable()->constrained()->nullOnDelete();
|
||||
$table->string('name', 255)->unique();
|
||||
$table->date('event_date');
|
||||
$table->string('poster', 255);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('events');
|
||||
}
|
||||
};
|
||||
@@ -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::dropIfExists('sessions');
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::create('sessions', static function (Blueprint $table) {
|
||||
$table->string('id')->primary();
|
||||
$table->foreignId('user_id')->nullable()->index();
|
||||
$table->string('ip_address', 45)->nullable();
|
||||
$table->text('user_agent')->nullable();
|
||||
$table->longText('payload');
|
||||
$table->integer('last_activity')->index();
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -1,10 +1,13 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\User;
|
||||
// use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
|
||||
class DatabaseSeeder extends Seeder
|
||||
{
|
||||
@@ -13,11 +16,15 @@ class DatabaseSeeder extends Seeder
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
// User::factory(10)->create();
|
||||
if (config('common.seeding.flush_cache') ?? false) {
|
||||
Cache::flush();
|
||||
}
|
||||
|
||||
User::factory()->create([
|
||||
'name' => 'Test User',
|
||||
'email' => 'test@example.com',
|
||||
|
||||
$this->call([
|
||||
UserSeeder::class,
|
||||
VenueSeeder::class,
|
||||
EventSeeder::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
20
database/seeders/EventSeeder.php
Normal file
20
database/seeders/EventSeeder.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Event;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
//use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
class EventSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
Event::factory(config('common.seeding.model.event.count'))->create();
|
||||
}
|
||||
}
|
||||
24
database/seeders/UserSeeder.php
Normal file
24
database/seeders/UserSeeder.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
//use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
|
||||
class UserSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
User::factory()->create([
|
||||
'name' => 'Jane Doe',
|
||||
'email' => 'jane.doe@example.com',
|
||||
]);
|
||||
}
|
||||
}
|
||||
23
database/seeders/VenueSeeder.php
Normal file
23
database/seeders/VenueSeeder.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Venue;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
//use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
|
||||
class VenueSeeder extends Seeder
|
||||
{
|
||||
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
Venue::factory(config('common.seeding.model.venue.count'))->create();
|
||||
//->hasEvents(3)->create(); //Impossible to count 50 events for 20 venues
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user