106 lines
3.0 KiB
PHP
106 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace Modules\Client\database\seeders;
|
|
|
|
use Illuminate\Support\Str;
|
|
use Illuminate\Database\Seeder;
|
|
use Modules\Client\app\Models\Client;
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
class ClientDatabaseSeeder extends Seeder
|
|
{
|
|
/**
|
|
* Run the database seeds.
|
|
*/
|
|
public function run(): void
|
|
{
|
|
// $this->call([]);
|
|
|
|
$clients = [
|
|
[
|
|
'image' => 'c7.png',
|
|
'uuid' => Str::uuid(),
|
|
'name' => 'logo',
|
|
'link' => 'example.com',
|
|
],
|
|
[
|
|
'image' => 'c1.png',
|
|
'uuid' => Str::uuid(),
|
|
'name' => 'chrome',
|
|
'link' => 'example.com',
|
|
],
|
|
[
|
|
'image' => 'c4.png',
|
|
'uuid' => Str::uuid(),
|
|
'name' => 'echo',
|
|
'link' => 'example.com',
|
|
],
|
|
[
|
|
'image' => 'c8.png',
|
|
'uuid' => Str::uuid(),
|
|
'name' => 'nutrifes',
|
|
'link' => 'example.com',
|
|
],
|
|
[
|
|
'image' => 'c2.png',
|
|
'uuid' => Str::uuid(),
|
|
'name' => 'cocacola',
|
|
'link' => 'example.com',
|
|
],
|
|
[
|
|
'image' => 'c3.png',
|
|
'uuid' => Str::uuid(),
|
|
'name' => 'delly',
|
|
'link' => 'example.com',
|
|
],
|
|
[
|
|
'image' => 'c5.png',
|
|
'uuid' => Str::uuid(),
|
|
'name' => 'google2',
|
|
'link' => 'example.com',
|
|
],
|
|
[
|
|
'image' => 'c6.png',
|
|
'uuid' => Str::uuid(),
|
|
'name' => 'gradeup',
|
|
'link' => 'example.com',
|
|
],
|
|
];
|
|
|
|
foreach ($clients as $client) {
|
|
$cmsactivity = Client::create([
|
|
'uuid' => Str::uuid(),
|
|
'name' => $client['name'],
|
|
'link' => $client['link'],
|
|
]);
|
|
|
|
// Add image to the created banner
|
|
$this->uploadImageForClient($client['image'], $cmsactivity);
|
|
}
|
|
|
|
}
|
|
|
|
private function uploadImageForClient(string $imageFileName, $cmsbanner)
|
|
{
|
|
$seederDirPath = 'clients/';
|
|
|
|
// Generate a unique filename for the new image
|
|
$newFileName = Str::uuid() . '.jpg';
|
|
|
|
// Storage path for the new image
|
|
$storagePath = '/clients/' . $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();
|
|
}
|
|
}
|
|
}
|