Skip to content

Commit

Permalink
Refactor database seeding and migration setup
Browse files Browse the repository at this point in the history
This commit introduces multiple changes including the usage of Album factory in DatabaseSeeder, changing the superadmin user's email, and addition of 'view_count' in pictures table. Additionally, improvements were made to handling unauthenticated user id scenario in activities table and alterations in PicturesRelationManager to create a table with one column.
  • Loading branch information
marco-introini committed Dec 24, 2023
1 parent e4c41a3 commit 3759f53
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public function form(Form $form): Form
->image()
->required()
->disk('images')
]);
])
->columns(1);
}

public function table(Table $table): Table
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public function up(): void
{
Schema::create('activities', function (Blueprint $table) {
$table->id();
$table->foreignIdFor(User::class);
$table->foreignIdFor(User::class)->nullable();
$table->text('log_message');
$table->string('model')->nullable();
$table->unsignedInteger('model_id')->nullable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ public function up(): void
{
Schema::create('pictures', function (Blueprint $table) {
$table->id();
$table->foreignIdFor(Album::class);
$table->foreignIdFor(Album::class)->constrained();
$table->string('name');
$table->string('image');
$table->text('description')->nullable();
$table->integer('view_count')->default(0);
$table->timestamps();
});
}
Expand Down
5 changes: 3 additions & 2 deletions database/seeders/DatabaseSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

// use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use App\Models\Activity;
use App\Models\Album;
use App\Models\User;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Hash;
Expand All @@ -18,7 +19,7 @@ public function run(): void
$superAdmin = User::factory()->create([
'username' => 'admin',
'name' => 'Test Super Admin',
'email' => 'test@example.com',
'email' => 'admin@example.com',
'email_verified_at' => now(),
'password' => Hash::make('password')
]);
Expand All @@ -36,6 +37,6 @@ public function run(): void

User::factory(10)->create();

Activity::factory(20)->create();
Album::factory(3)->create();
}
}

0 comments on commit 3759f53

Please sign in to comment.