firstcommit
This commit is contained in:
0
Modules/Gallery/database/factories/.gitkeep
Normal file
0
Modules/Gallery/database/factories/.gitkeep
Normal file
0
Modules/Gallery/database/migrations/.gitkeep
Normal file
0
Modules/Gallery/database/migrations/.gitkeep
Normal file
@@ -0,0 +1,38 @@
|
||||
<?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('galleries', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->uuid();
|
||||
$table->unsignedBigInteger('gallery_category_id');
|
||||
$table->text('detail')->nullable();
|
||||
$table->string('image')->nullable();
|
||||
$table->string('image_path')->nullable();
|
||||
$table->string('video_link')->nullable();
|
||||
$table->string('status')->default('active');
|
||||
$table->softDeletes();
|
||||
$table->timestamps();
|
||||
|
||||
// Define foreign key constraint
|
||||
$table->foreign('gallery_category_id')->references('id')->on('gallery_categories')->onDelete('cascade');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('galleries');
|
||||
}
|
||||
};
|
@@ -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('gallery_categories', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->uuid();
|
||||
$table->string('type')->nullable();
|
||||
$table->string('category')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('gallery_categories');
|
||||
}
|
||||
|
||||
};
|
0
Modules/Gallery/database/seeders/.gitkeep
Normal file
0
Modules/Gallery/database/seeders/.gitkeep
Normal file
78
Modules/Gallery/database/seeders/GalleryDatabaseSeeder.php
Normal file
78
Modules/Gallery/database/seeders/GalleryDatabaseSeeder.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Gallery\database\seeders;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Modules\Gallery\app\Models\Gallery;
|
||||
use Modules\Gallery\app\Models\GalleryCategory;
|
||||
|
||||
class GalleryDatabaseSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
//-- galleryCategories
|
||||
$galleryCategories = [
|
||||
'surgery',
|
||||
'sample collection',
|
||||
];
|
||||
|
||||
foreach ($galleryCategories as $category) {
|
||||
GalleryCategory::create([
|
||||
'uuid' => Str::uuid(),
|
||||
'category' => $category,
|
||||
'type' => 'image',
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//-- galleries
|
||||
$galleries = [
|
||||
['detail' => 'hair transplant 1', 'image' => 'g1.jpg'],
|
||||
['detail' => 'hair transplant 2', 'image' => 'g2.jpg'],
|
||||
['detail' => 'hair transplant 3', 'image' => 'g3.jpg'],
|
||||
['detail' => 'hair transplant 4', 'image' => 'g4.jpg'],
|
||||
['detail' => 'hair transplant 5', 'image' => 'g5.jpg'],
|
||||
];
|
||||
|
||||
foreach ($galleries as $gallery) {
|
||||
$galleryCategoriesIdInRandomOrder = GalleryCategory::all()->random()->id;
|
||||
$cmsGallery = Gallery::create([
|
||||
'uuid' => Str::uuid(),
|
||||
'gallery_category_id' => $galleryCategoriesIdInRandomOrder,
|
||||
'detail' => $gallery['detail'],
|
||||
]);
|
||||
|
||||
// Add image to the created banner
|
||||
$this->uploadImageForGallery($gallery['image'], $cmsGallery);
|
||||
}
|
||||
}
|
||||
|
||||
private function uploadImageForGallery(string $imageFileName, $cmsbanner)
|
||||
{
|
||||
$seederDirPath = 'galleries/';
|
||||
|
||||
// Generate a unique filename for the new image
|
||||
$newFileName = Str::uuid() . '.jpg';
|
||||
|
||||
// Storage path for the new image
|
||||
$storagePath = '/galleries/' . $newFileName;
|
||||
|
||||
// Check if the image exists in the seeder_disk
|
||||
if (Storage::disk('seeder_disk')->exists($seederDirPath . $imageFileName)) {
|
||||
// Copy the image from seeder to public
|
||||
$fileContents = Storage::disk('seeder_disk')->get($seederDirPath . $imageFileName);
|
||||
|
||||
Storage::disk('public_uploads')->put($storagePath, $fileContents);
|
||||
|
||||
$cmsbanner->image = $newFileName;
|
||||
$cmsbanner->image_path = $storagePath;
|
||||
$cmsbanner->save();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user