firstcommit
This commit is contained in:
0
Modules/Client/database/factories/.gitkeep
Normal file
0
Modules/Client/database/factories/.gitkeep
Normal file
0
Modules/Client/database/migrations/.gitkeep
Normal file
0
Modules/Client/database/migrations/.gitkeep
Normal file
@@ -0,0 +1,33 @@
|
||||
<?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('clients', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->uuid();
|
||||
$table->string('name');
|
||||
$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('clients');
|
||||
}
|
||||
};
|
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
namespace Modules\Client;
|
||||
|
||||
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::table('clients', function (Blueprint $table) {
|
||||
$table->string('link', 10000)->nullable()->after('name');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('clients', function (Blueprint $table) {
|
||||
$table->dropColumn('link');
|
||||
});
|
||||
}
|
||||
};
|
0
Modules/Client/database/seeders/.gitkeep
Normal file
0
Modules/Client/database/seeders/.gitkeep
Normal file
105
Modules/Client/database/seeders/ClientDatabaseSeeder.php
Normal file
105
Modules/Client/database/seeders/ClientDatabaseSeeder.php
Normal file
@@ -0,0 +1,105 @@
|
||||
<?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();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user