75 lines
2.5 KiB
PHP
75 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use App\Lib\Utils;
|
|
use App\Models\Gamme;
|
|
use App\Models\Product;
|
|
use Illuminate\Database\Seeder;
|
|
use SplFileInfo;
|
|
use Illuminate\Support\Str;
|
|
|
|
class GammesSeeder extends Seeder
|
|
{
|
|
/**
|
|
* Run the database seeds.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function run()
|
|
{
|
|
$tabGammes = [];
|
|
|
|
Gamme::factory(4)->create()
|
|
->each(function (Gamme $gamme) use (&$tabGammes) {
|
|
array_push($tabGammes, $gamme->color);
|
|
});
|
|
|
|
$upload = new SplFileInfo(resource_path('assets/images/cookrange.jpg'));
|
|
$picture = new Gamme();
|
|
$imgpath = Utils::storeImage($upload, $picture->getTable());
|
|
$upload = new SplFileInfo(resource_path('assets/images/entete_sous_gammes.jpg'));
|
|
$bannerpath = Utils::storeImage($upload, $picture->getTable());
|
|
|
|
foreach ($tabGammes as $key => $value) {
|
|
for ($i = 0; $i < 2; $i++) {
|
|
$gamme = new Gamme();
|
|
$id = $key + 1;
|
|
$gamme->parent_gamme_id = $id;
|
|
$gamme->title = 'lorem ipsum' . $id . $i;
|
|
$gamme->slug = Str::slug($gamme->title);
|
|
$gamme->text = 'lorem ipsum set doloris' . $id . $i;
|
|
$gamme->color = $value;
|
|
$gamme->picture = $imgpath;
|
|
$gamme->alt_text_picture = 'lorem utus garis' . $id . $i;
|
|
$gamme->banner = $bannerpath;
|
|
$gamme->alt_text_banner = 'redus faeros' . $id . $i;
|
|
$gamme->save();
|
|
|
|
Product::factory(rand(1, 10))->make()
|
|
->each(function (Product $product) use (&$gamme) {
|
|
$product->gamme_id = $gamme->id;
|
|
$product->save();
|
|
});
|
|
}
|
|
}
|
|
$gamme = new Gamme();
|
|
$id = $gamme->id;
|
|
$gamme->parent_gamme_id = null;
|
|
$gamme->title = 'lorem ipsum' . $id . $i;
|
|
$gamme->slug = Str::slug($gamme->title);
|
|
$gamme->text = 'lorem gurus et ipsum set doloris' . $id . $i;
|
|
$gamme->color = '#ffa58' . rand(1, 9);
|
|
$gamme->picture = $imgpath;
|
|
$gamme->alt_text_picture = 'lorem utus garis' . $id . $i;
|
|
$gamme->banner = $bannerpath;
|
|
$gamme->alt_text_banner = 'redus faros' . $id . $i;
|
|
$gamme->save();
|
|
|
|
Product::factory(4)->make()
|
|
->each(function (Product $product) use (&$gamme) {
|
|
$product->gamme_id = $gamme->id;
|
|
$product->save();
|
|
});
|
|
}
|
|
}
|