Files
aroginhealthcare/Modules/AboutUs/database/seeders/AboutUsDatabaseSeeder.php
2025-08-17 16:23:14 +05:45

50 lines
1.3 KiB
PHP

<?php
namespace Modules\AboutUs\database\seeders;
use Illuminate\Support\Str;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Storage;
use Modules\AboutUs\app\Models\AboutUs;
class AboutUsDatabaseSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
// $this->call([]);
$aboutUs = new AboutUs();
$aboutUs->title = 'about us';
$aboutUs->save();
// Add image to the created banner
$this->uploadImageForBanner('test_video.mp4.', $aboutUs);
}
private function uploadImageForBanner(string $imageFileName, $cmsbanner)
{
$seederDirPath = 'aboutUs/';
// Generate a unique filename for the new image
$newFileName = Str::uuid() . '.mp4';
// Storage path for the new image
$storagePath = '/aboutUs/' . $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->filename = $newFileName;
$cmsbanner->save();
}
}
}