added slider seeder

added slider image seeder
pull/49/head
A1Gard 5 months ago
parent 35b2ba64eb
commit 03ffcc7638

@ -48,7 +48,7 @@ php artisan serv
```bash
php artisan seeding:prepare
```
- Seeding image for models: [Group, Category, Post, Products]
- Seeding image for models: [Group, Category, Post, Product, Slider]
```bash
pa seeding:image Product digital
```

@ -6,6 +6,7 @@ use App\Models\Category;
use App\Models\Group;
use App\Models\Post;
use App\Models\Product;
use App\Models\Slider;
use Illuminate\Console\Command;
use Spatie\Image\Enums\AlignPosition;
use Spatie\Image\Enums\Fit;
@ -47,6 +48,7 @@ class SeedingImage extends Command
$tempName = explode('.', $name);
$item->name = readable($tempName[0]) . ' model ' . $item->id;
}
$item->status = 1;
$item->addMedia($images[0]->getRealPath())
->preservingOriginal() //middle method
->toMediaCollection(); //finishing method
@ -99,15 +101,32 @@ class SeedingImage extends Command
$item->save();
}
break;
case 'Slider':
foreach (Slider::all() as $item) {
$this->info('Slider: ' . $item->name . ' adding image...');
shuffle($images);
if (!\File::exists(storage_path().'/app/public/sliders/')){
mkdir(storage_path().'/app/public/sliders/', 0755, true);
}
\File::copy($images[0]->getRealPath(),storage_path().'/app/public/sliders/' . $images[0]->getFilename());
$item->image = $images[0]->getFilename();
$i = Image::load($images[0]->getRealPath())
->optimize()
->format('webp');
$i->save(storage_path() . '/app/public/sliders/optimized-'. $item->image);
$item->status = 1;
$item->save();
}
break;
case 'Post':
foreach (Post::all() as $item) {
$this->info('post: ' . $item->id . ' adding image...');
shuffle($images);
$name = $images[0]->getFilename();
$item->addMedia($images[0]->getRealPath())
->preservingOriginal() //middle method
->toMediaCollection(); //finishing method
$item->save();
$item->status = 1;
}
break;
default:

@ -26,6 +26,9 @@ class ProductFactory extends Factory
'user_id' => 1,
'category_id' => $rand,
'description' => $this->faker->realText(600),
'stock_quantity' => rand(1,7),
'price' => rand(1,100),
'sku' => $this->faker->unique()->ean8(),
];
}
}

@ -2,6 +2,7 @@
namespace Database\Factories;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
@ -17,7 +18,8 @@ class SliderFactory extends Factory
public function definition(): array
{
return [
//
'body' => $this->faker->paragraph(),
'user_id' => 1,
];
}
}

@ -14,7 +14,7 @@ return new class extends Migration
Schema::create('sliders', function (Blueprint $table) {
$table->id();
$table->text('body');
$table->string('image');
$table->string('image')->nullable();
$table->string('tag')->nullable();
$table->unsignedBigInteger('user_id');
$table->unsignedTinyInteger('status')->default(0);

@ -41,6 +41,7 @@ class DatabaseSeeder extends Seeder
VisitorSeeder::class,
TransportSeeder::class,
MenuSeeder::class,
SliderSeeder::class,
]
);
}

@ -26,13 +26,13 @@ class GfxSeeder extends Seeder
'key'=>'primary',
'label'=>'Primary color',
'system'=>'1',
'value'=> '#6e0000'
'value'=> '#03b2b5'
],
[
'key'=>'secondary',
'label'=>'Secondary color',
'system'=>'1',
'value'=> '#ff0000'
'value'=> '#0064c2'
],
[
'key'=>'text',

@ -2,6 +2,7 @@
namespace Database\Seeders;
use App\Models\Slider;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
@ -13,5 +14,6 @@ class SliderSeeder extends Seeder
public function run(): void
{
//
Slider::factory(4)->create();
}
}

@ -89,6 +89,11 @@
<li class="icon-menu">
<a href="#">
<i class="ri-shopping-bag-2-line"></i>
<span class="badge bg-danger card-count">
@if(cardCount() > 0)
{{cardCount()}}
@endif
</span>
</a>
</li>
<li id="toggler-menu" class="icon-menu">

@ -382,6 +382,7 @@ Route::middleware([\App\Http\Middleware\VisitorCounter::class])
Route::get('/attachments', [\App\Http\Controllers\ClientController::class,'attachments'])->name('attachments');
Route::get('/attachment/{attachment}', [\App\Http\Controllers\ClientController::class,'attachment'])->name('attachment');
Route::get('/tag/{slug}', [\App\Http\Controllers\ClientController::class,'tag'])->name('tag'); // wip
Route::get('/group/{slug}', [\App\Http\Controllers\ClientController::class,'group'])->name('group'); // wip
Route::get('/product/{product}', [\App\Http\Controllers\ClientController::class,'product'])->name('product');
Route::get('/video/{clip}', [\App\Http\Controllers\ClientController::class,'clip'])->name('clip');
Route::get('/category/{category}', [\App\Http\Controllers\ClientController::class,'category'])->name('category');

Loading…
Cancel
Save