firstcommit
This commit is contained in:
0
Modules/Banner/database/factories/.gitkeep
Normal file
0
Modules/Banner/database/factories/.gitkeep
Normal file
0
Modules/Banner/database/migrations/.gitkeep
Normal file
0
Modules/Banner/database/migrations/.gitkeep
Normal file
@@ -0,0 +1,36 @@
|
||||
<?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('banners', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->uuid();
|
||||
$table->string('title');
|
||||
$table->integer('ordering');
|
||||
$table->string('caption')->nullable();
|
||||
$table->string('link')->nullable();
|
||||
$table->string('image')->nullable();
|
||||
$table->string('image_path')->nullable();
|
||||
$table->string('status')->default('active');
|
||||
$table->softDeletes();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('banners');
|
||||
}
|
||||
};
|
0
Modules/Banner/database/seeders/.gitkeep
Normal file
0
Modules/Banner/database/seeders/.gitkeep
Normal file
71
Modules/Banner/database/seeders/BannerDatabaseSeeder.php
Normal file
71
Modules/Banner/database/seeders/BannerDatabaseSeeder.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Banner\database\seeders;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Modules\Banner\app\Models\Banner;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class BannerDatabaseSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$banners = [
|
||||
[
|
||||
'title' => 'Adventure Awaits',
|
||||
'link' => 'https://jhigucms.com/adventure-awaits',
|
||||
'ordering' => 1,
|
||||
'caption' => 'Embark on an exciting journey with us. Discover new places and create lasting memories.',
|
||||
'image' => '2.jpg'
|
||||
],
|
||||
[
|
||||
'title' =>'Journey of Discovery',
|
||||
'link' => 'https://jhigucms.com/adventure-awaits',
|
||||
'ordering' => 2,
|
||||
'caption' => 'Discover hidden gems and make every moment count on your travels.',
|
||||
'image' => '1.jpg'
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($banners as $banner) {
|
||||
$cmsbanner = Banner::create([
|
||||
'uuid' => Str::uuid(),
|
||||
'title' => $banner['title'],
|
||||
'link' => $banner['link'],
|
||||
'ordering' => $banner['ordering'],
|
||||
'caption' => $banner['caption'],
|
||||
]);
|
||||
|
||||
// Add image to the created banner
|
||||
$this->uploadImageForBanner($banner['image'], $cmsbanner);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private function uploadImageForBanner(string $imageFileName, $cmsbanner)
|
||||
{
|
||||
$seederDirPath = 'banners/';
|
||||
|
||||
// Generate a unique filename for the new image
|
||||
$newFileName = Str::uuid() . '.jpg';
|
||||
|
||||
// Storage path for the new image
|
||||
$storagePath = '/banners/' . $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