diff --git a/app/Models/Gamme.php b/app/Models/Gamme.php index 208c6d1..e24b41a 100644 --- a/app/Models/Gamme.php +++ b/app/Models/Gamme.php @@ -30,7 +30,9 @@ class Gamme extends Model 'title', 'slug', 'text', + 'picture', 'alt_text_picture', + 'banner', 'alt_text_banner', ]; @@ -38,10 +40,10 @@ class Gamme extends Model protected static function boot() { static::creating(function (Gamme $gamme) { - if ($gamme->picture) { + if (is_a($gamme->picture,"SplFileInfo")) { $gamme->picture = Utils::storeImage($gamme->picture, $gamme->getTable()); } - if ($gamme->banner) { + if (is_a($gamme->banner,"SplFileInfo")) { $gamme->banner = Utils::storeImage($gamme->banner, $gamme->getTable()); } @@ -52,10 +54,10 @@ class Gamme extends Model }); static::updating(function (Gamme $gamme) { - if ($gamme->picture) { + if (is_a($gamme->picture,"SplFileInfo")) { $gamme->picture = Utils::storeImage($gamme->picture, $gamme->getTable()); } - if ($gamme->banner) { + if (is_a($gamme->banner,"SplFileInfo")) { $gamme->banner = Utils::storeImage($gamme->banner, $gamme->getTable()); } if ($gamme->parent_gamme_id === null) { diff --git a/database/factories/GammeFactory.php b/database/factories/GammeFactory.php index b93d2a3..2b9d439 100644 --- a/database/factories/GammeFactory.php +++ b/database/factories/GammeFactory.php @@ -2,6 +2,8 @@ namespace Database\Factories; +use App\Lib\Utils; +use App\Models\Gamme; use Illuminate\Database\Eloquent\Factories\Factory; use SplFileInfo; use Illuminate\Support\Str; @@ -17,15 +19,21 @@ class GammeFactory extends Factory { $title = $this->faker->text(10) . rand(1, 100); + $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()); + return [ 'parent_gamme_id' => null, 'title' => $title, 'slug' => Str::slug($title), 'text' => $this->faker->text(5), 'color' => $this->faker->hexColor(), - 'picture' => new SplFileInfo(resource_path('assets/images/cookrange.jpg')), + 'picture' => $imgpath, 'alt_text_picture' => $this->faker->sentence(10), - 'banner' => new SplFileInfo(resource_path('assets/images/entete_sous_gammes.jpg')), + 'banner' => $bannerpath, 'alt_text_banner' => $this->faker->sentence(10), ]; } diff --git a/database/factories/ProductFactory.php b/database/factories/ProductFactory.php index 82118f1..94b33ac 100644 --- a/database/factories/ProductFactory.php +++ b/database/factories/ProductFactory.php @@ -99,8 +99,8 @@ class ProductFactory extends Factory ); $upload = new SplFileInfo(resource_path('assets/images/product_sample_01.png')); - $picto = new Product(); - $imgpath = Utils::storeImage($upload, $picto->getTable()); + $picture = new Product(); + $imgpath = Utils::storeImage($upload, $picture->getTable()); return [ 'name' => $name, diff --git a/database/seeders/GammesSeeder.php b/database/seeders/GammesSeeder.php index 7c5a6c0..0546668 100644 --- a/database/seeders/GammesSeeder.php +++ b/database/seeders/GammesSeeder.php @@ -2,6 +2,7 @@ namespace Database\Seeders; +use App\Lib\Utils; use App\Models\Gamme; use App\Models\Product; use Illuminate\Database\Seeder; @@ -24,6 +25,12 @@ class GammesSeeder extends Seeder 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(); @@ -33,9 +40,9 @@ class GammesSeeder extends Seeder $gamme->slug = Str::slug($gamme->title); $gamme->text = 'lorem ipsum set doloris' . $id . $i; $gamme->color = $value; - $gamme->picture = new SplFileInfo(resource_path('assets/images/cookrange.jpg')); + $gamme->picture = $imgpath; $gamme->alt_text_picture = 'lorem utus garis' . $id . $i; - $gamme->banner = new SplFileInfo(resource_path('assets/images/entete_sous_gammes.jpg')); + $gamme->banner = $bannerpath; $gamme->alt_text_banner = 'redus faeros' . $id . $i; $gamme->save(); @@ -53,9 +60,9 @@ class GammesSeeder extends Seeder $gamme->slug = Str::slug($gamme->title); $gamme->text = 'lorem gurus et ipsum set doloris' . $id . $i; $gamme->color = '#ffa58' . rand(1, 9); - $gamme->picture = new SplFileInfo(resource_path('assets/images/cookrange.jpg')); + $gamme->picture = $imgpath; $gamme->alt_text_picture = 'lorem utus garis' . $id . $i; - $gamme->banner = new SplFileInfo(resource_path('assets/images/cat_bckg.jpg')); + $gamme->banner = $bannerpath; $gamme->alt_text_banner = 'redus faros' . $id . $i; $gamme->save(); diff --git a/resources/views/back/gammes/form-inputs.blade.php b/resources/views/back/gammes/form-inputs.blade.php index 5f78079..aa758d7 100644 --- a/resources/views/back/gammes/form-inputs.blade.php +++ b/resources/views/back/gammes/form-inputs.blade.php @@ -11,7 +11,7 @@

- @if ($gamme->picture !== null) + @if (!empty($gamme->picture))

{{$gamme->alt_text_picture}} @@ -26,7 +26,7 @@

- @if ($gamme->banner !== null) + @if (!empty($gamme->banner))

{{$gamme->alt_text_banner}} diff --git a/resources/views/back/gammes/index.blade.php b/resources/views/back/gammes/index.blade.php index f86d43a..5a1dd0b 100644 --- a/resources/views/back/gammes/index.blade.php +++ b/resources/views/back/gammes/index.blade.php @@ -31,7 +31,7 @@ {{$gamme->title}} @endif {{$gamme->text}} - + @if (!empty($gamme->picture))@endif @if (isset($gamme->parentGamme)) @@ -50,4 +50,4 @@ @endforeach -@endsection \ No newline at end of file +@endsection