encode json in update product

This commit is contained in:
Sebastien Hattry 2022-01-06 17:50:26 +01:00
parent 65885730bb
commit 42af8d3b8d
20 changed files with 195 additions and 110 deletions

View file

@ -15,10 +15,24 @@ class GammesController extends Controller
return view('front.gammes.index', compact('gammes', 'nb_gammes'));
}
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
public function show(Gamme $gamme)
{
$products = Product::where('gamme_id', $gamme->id)->orderBy('name')->get();
$gammes = collect([]);
$dbGammes = Gamme::where('id', $gamme->id)
->with('childGammes')->get();
/** @var \App\Models\Gamme $dbGamme */
foreach ($dbGammes as $dbGamme) {
$gammes->push($dbGamme->id);
$dbGamme->childGammes->sortBy('title')
->map(function (Gamme $childGamme) use (&$gammes) {
$gammes->push($childGamme->id);
});
}
$products = Product::whereIn('gamme_id', $gammes)
->orderBy('name')
->get();
return view('front.gammes.show', compact('gamme', 'products'));
}

View file

@ -52,8 +52,10 @@ class InitVarsGlobals
['date_end', '>', Carbon::now()->format('Y-m-d H:i:s')],
['on_top', true]
])->first();
$products_home = Product::where('is_on_top', true)->get();
$products_food = Product::where('is_food_service', true)->get();
// Limitation à 3 produits affichés sur la homepage
$products_home = Product::where('is_on_top', true)->take(3)->get();
// Limitation à 6 produits affichés sur la page Food Service
$products_food = Product::where('is_food_service', true)->take(6)->get();
$pictos_marqueBloc2 = Picto::where('page', Page::marqueBloc2()->value)->get();
$pictos_food = Picto::where('page', Page::foodBloc2()->value)->get();

View file

@ -14,13 +14,104 @@ class StoreProductRequest extends FormRequest
*/
public function authorize()
{
$tabFour = array(
'id' => 0,
'name' => 'Four',
'url' => '/assets/images/four.png',
'time' => $this->time_cook0,
'temp' => $this->temp_cook0,
'status' => $this->is_activated0 ? true : false
);
$tabFriteuse = array(
'id' => 1,
'name' => 'Friteuse',
'url' => '/assets/images/friteuse.png',
'time' => $this->time_cook1,
'temp' => $this->temp_cook1,
'status' => $this->is_activated1 ? true : false
);
$tabPoele = array(
'id' => 2,
'name' => 'Poêle',
'url' => '/assets/images/poele.png',
'time' => $this->time_cook2,
'temp' => $this->temp_cook2,
'status' => $this->is_activated2 ? true : false
);
$tabCocotte = array(
'id' => 3,
'name' => 'Cocotte',
'url' => '/assets/images/cocotte.png',
'time' => $this->time_cook3,
'temp' => $this->temp_cook3,
'status' => $this->is_activated3 ? true : false
);
$tabPlancha = array(
'id' => 4,
'name' => 'Plancha',
'url' => '/assets/images/plancha.png',
'time' => $this->time_cook4,
'temp' => $this->temp_cook4,
'status' => $this->is_activated4 ? true : false
);
$tabBainMarie = array(
'id' => 5,
'name' => 'Bain Marie',
'url' => '/assets/images/bainmarie.png',
'time' => $this->time_cook5,
'temp' => $this->temp_cook5,
'status' => $this->is_activated5 ? true : false
);
$tabBarbecue = array(
'id' => 6,
'name' => 'Barbecue',
'url' => '/assets/images/barbecue.png',
'time' => $this->time_cook6,
'temp' => $this->temp_cook6,
'status' => $this->is_activated6 ? true : false
);
$tabMicroOndes = array(
'id' => 7,
'name' => 'Micro Ondes',
'url' => '/assets/images/microondes.png',
'time' => $this->time_cook7,
'temp' => $this->temp_cook7,
'status' => $this->is_activated7 ? true : false
);
$tabPlusProduit1 = array(
'id' => 0,
'name' => $this->content0,
'url' => '/assets/images/sans-label.jpg',
);
$tabPlusProduit2 = array(
'id' => 1,
'name' => $this->content1,
'url' => '/assets/images/sans-label.jpg',
);
$tabPlusProduit3 = array(
'id' => 2,
'name' => $this->content2,
'url' => '/assets/images/sans-label.jpg',
);
$this->merge([
'slug' => Str::slug($this->name),
'gamme_id' => $this->gamme_id === '0' ? null : $this->gamme_id,
'sous_gamme_id' => $this->sous_gamme_id === '0' ? null : $this->sous_gamme_id,
'pictos' => json_encode([
'four' => $tabFour,
'friteuse' => $tabFriteuse,
'poele' => $tabPoele,
'cocotte' => $tabCocotte,
'plancha' => $tabPlancha,
'bainmarie' => $tabBainMarie,
'barbecue' => $tabBarbecue,
'microondes' => $tabMicroOndes
]),
'plusproduit' => json_encode([$tabPlusProduit1, $tabPlusProduit2, $tabPlusProduit3]),
'is_published' => $this->is_published ? true : false,
'is_on_top' => $this->is_on_top ? true : false,
'is_food_service' => $this->is_food_service ? true : false,
'is_halal' => $this->is_halal ? true : false,
]);
return auth()->check();
@ -34,16 +125,18 @@ class StoreProductRequest extends FormRequest
public function rules()
{
return [
'gamme_id' => 'required|exists:gammes,id',
'sous_gamme_id' => 'sometimes|nullable|exists:gammes,id',
'gamme_id' => 'sometimes|nullable|exists:gammes,id',
'name' => 'required|max:255',
'slug' => 'required|unique:products',
'description' => 'required|min:20',
'picture' => 'required|image|mimes:png|max:1024|dimensions:width=509,height=509',
'alt_text_picture' => 'required|max:255',
'pictos' => 'sometimes|nullable',
'plusproduit' => 'sometimes|nullable',
'is_published' => 'nullable|boolean',
'is_on_top' => 'nullable|boolean',
'is_food_service' => 'nullable|boolean',
'is_halal' => 'nullable|boolean',
// 'seo_title' => 'required|max:255',
// 'seo_description' => 'required|max:255',
];

View file

@ -12,7 +12,6 @@ class Product extends Model
protected $fillable = [
'gamme_id',
'sous_gamme_id',
'name',
'slug',
'description',
@ -57,12 +56,4 @@ class Product extends Model
{
return $this->belongsTo(Gamme::class);
}
/**
* Get the Range that owns the product.
*/
public function sousGamme()
{
return $this->belongsTo(Gamme::class);
}
}

View file

@ -36,8 +36,8 @@ class ProductFactory extends Factory
'id' => 2,
'name' => 'Poêle',
'url' => '/assets/images/poele.png',
'time' => '',
'temp' => '',
'time' => '5 minutes sur chaque face',
'temp' => '100°C',
'status' => false
);
$tabCocotte = array(
@ -52,32 +52,32 @@ class ProductFactory extends Factory
'id' => 4,
'name' => 'Plancha',
'url' => '/assets/images/plancha.png',
'time' => '',
'temp' => '',
'time' => '20mins',
'temp' => '130°C',
'status' => false
);
$tabBainMarie = array(
'id' => 5,
'name' => 'Bain Marie',
'url' => '/assets/images/bainmarie.png',
'time' => '',
'temp' => '',
'time' => '30 mins à 45 mins',
'temp' => '80°C',
'status' => false
);
$tabBarbecue = array(
'id' => 6,
'name' => 'Barbecue',
'url' => '/assets/images/barbecue.png',
'time' => '',
'temp' => '',
'time' => '30 minutes',
'temp' => '200°C',
'status' => false
);
$tabMicroOndes = array(
'id' => 7,
'name' => 'Micro Ondes',
'url' => '/assets/images/microondes.png',
'time' => '',
'temp' => '',
'time' => '3mins',
'temp' => '900 Watts',
'status' => false
);
$tabPlusProduit1 = array(
@ -115,6 +115,7 @@ class ProductFactory extends Factory
'is_published' => true,
'is_on_top' => false,
'is_food_service' => false,
'is_halal' => true,
'seo_title' => $this->faker->text(5),
'seo_description' => $this->faker->sentence(20),
];

View file

@ -16,11 +16,11 @@ class CreateEncartsTable extends Migration
Schema::create('encarts', function (Blueprint $table) {
$table->id();
$table->smallInteger('page');
$table->string('title');
$table->string('subtitle');
$table->text('title');
$table->text('subtitle');
$table->text('text');
$table->string('picture')->nullable();
$table->string('alt_text_picture')->nullable();
$table->text('picture')->nullable();
$table->text('alt_text_picture')->nullable();
$table->timestamps();
});
}

View file

@ -15,9 +15,9 @@ class CreateSlidersTable extends Migration
{
Schema::create('sliders', function (Blueprint $table) {
$table->id();
$table->string('label');
$table->text('label');
$table->string('slug')->unique();
$table->string('commentaire')->nullable();
$table->text('commentaire')->nullable();
$table->boolean('published')->default(false);
$table->timestamps();
});

View file

@ -17,12 +17,12 @@ class CreateSlidesTable extends Migration
$table->id();
$table->foreignId('slider_id')->default(1)->constrained('sliders');
$table->string('title');
$table->text('title');
$table->text('text')->nullable();
$table->string('picture')->nullable();
$table->string('alt_text_picture')->nullable();
$table->string('link_label')->nullable();
$table->string('link')->nullable();
$table->text('picture')->nullable();
$table->text('alt_text_picture')->nullable();
$table->text('link_label')->nullable();
$table->text('link')->nullable();
$table->boolean('link_new_tab')->default(false);
$table->integer('order')->default(1);

View file

@ -16,8 +16,8 @@ class CreatePictosTable extends Migration
Schema::create('pictos', function (Blueprint $table) {
$table->id();
$table->smallInteger('page');
$table->string('picture')->nullable();
$table->string('alt_text_picture')->nullable();
$table->text('picture')->nullable();
$table->text('alt_text_picture')->nullable();
$table->text('text');
$table->timestamps();
});

View file

@ -15,10 +15,10 @@ class CreatePictoBrandsTable extends Migration
{
Schema::create('picto_brands', function (Blueprint $table) {
$table->id();
$table->string('title');
$table->string('picture')->nullable();
$table->string('alt_text_picture')->nullable();
$table->string('text');
$table->text('title');
$table->text('picture')->nullable();
$table->text('alt_text_picture')->nullable();
$table->text('text');
$table->timestamps();
});
}

View file

@ -16,8 +16,8 @@ class CreateTitlesTable extends Migration
Schema::create('titles', function (Blueprint $table) {
$table->id();
$table->smallInteger('page')->unique();
$table->string('title');
$table->string('text')->nullable();
$table->text('title');
$table->text('text')->nullable();
$table->timestamps();
});
}

View file

@ -16,7 +16,7 @@ class CreateTextsTable extends Migration
Schema::create('texts', function (Blueprint $table) {
$table->id();
$table->smallInteger('page');
$table->string('title');
$table->text('title');
$table->text('text');
$table->timestamps();
});

View file

@ -15,14 +15,14 @@ class CreateAdviceTable extends Migration
{
Schema::create('advice', function (Blueprint $table) {
$table->id();
$table->string('title1');
$table->string('title2');
$table->string('picture1')->nullable();
$table->string('alt_text_picture1')->nullable();
$table->string('picture2')->nullable();
$table->string('alt_text_picture2')->nullable();
$table->string('picture3')->nullable();
$table->string('alt_text_picture3')->nullable();
$table->text('title1');
$table->text('title2');
$table->text('picture1')->nullable();
$table->text('alt_text_picture1')->nullable();
$table->text('picture2')->nullable();
$table->text('alt_text_picture2')->nullable();
$table->text('picture3')->nullable();
$table->text('alt_text_picture3')->nullable();
$table->text('text1');
$table->text('text2');
$table->timestamps();

View file

@ -15,12 +15,12 @@ class CreatePostsTable extends Migration
{
Schema::create('posts', function (Blueprint $table) {
$table->id();
$table->string('title');
$table->text('title');
$table->mediumText('text');
$table->string('picture_home')->nullable();
$table->string('alt_text_picture_home')->nullable();
$table->string('picture_news')->nullable();
$table->string('alt_text_picture_news')->nullable();
$table->text('picture_home')->nullable();
$table->text('alt_text_picture_home')->nullable();
$table->text('picture_news')->nullable();
$table->text('alt_text_picture_news')->nullable();
$table->timestamp('date_start')->nullable();
$table->timestamp('date_end')->nullable();
$table->boolean('on_top')->default(false);

View file

@ -16,14 +16,14 @@ class CreateGammesTable extends Migration
Schema::create('gammes', function (Blueprint $table) {
$table->id();
$table->foreignId('parent_gamme_id')->nullable();
$table->string('title');
$table->text('title');
$table->string('slug')->unique();
$table->text('text');
$table->string('color')->nullable();
$table->string('picture')->nullable();
$table->string('alt_text_picture')->nullable();
$table->string('banner')->nullable();
$table->string('alt_text_banner')->nullable();
$table->text('picture')->nullable();
$table->text('alt_text_picture')->nullable();
$table->text('banner')->nullable();
$table->text('alt_text_banner')->nullable();
$table->timestamps();
});
}

View file

@ -15,20 +15,20 @@ class CreateProductsTable extends Migration
{
Schema::create('products', function (Blueprint $table) {
$table->id();
$table->foreignId('gamme_id');
$table->foreignId('sous_gamme_id')->nullable();
$table->string('name');
$table->foreignId('gamme_id')->nullable();
$table->text('name');
$table->string('slug')->unique();
$table->text('description');
$table->string('picture')->nullable();
$table->string('alt_text_picture')->nullable();
$table->text('picture')->nullable();
$table->text('alt_text_picture')->nullable();
$table->mediumText('pictos');
$table->mediumText('plusproduit');
$table->boolean('is_published');
$table->boolean('is_on_top');
$table->boolean('is_food_service');
$table->string('seo_title');
$table->string('seo_description');
$table->boolean('is_halal');
$table->text('seo_title');
$table->text('seo_description');
$table->timestamps();
});
}

View file

@ -41,8 +41,7 @@ class GammesSeeder extends Seeder
Product::factory(rand(1, 10))->make()
->each(function (Product $product) use (&$gamme) {
$product->gamme_id = $gamme->parent_gamme_id;
$product->sous_gamme_id = $gamme->id;
$product->gamme_id = $gamme->id;
$product->save();
});
}
@ -63,7 +62,6 @@ class GammesSeeder extends Seeder
Product::factory(4)->make()
->each(function (Product $product) use (&$gamme) {
$product->gamme_id = $gamme->id;
$product->sous_gamme_id = null;
$product->save();
});
}

View file

@ -11,22 +11,6 @@
</select>
</div>
@include('back.modules.input-error', ['inputName'=>'gamme_id'])
@if (isset($product->gamme_id))
<div class="form-group">
<label for="sous_gamme_id">{{ __('Sous-gamme') }}</label>
<select class="custom-select" id="sous_gamme_id" name="sous_gamme_id">
<option value="0">Pas de sous-gamme</option>
@foreach($gammes as $gamme)
@foreach ($gamme->childGammes as $childGamme)
@if ($childGamme->parent_gamme_id === $product->gamme_id)
<option value="{{$childGamme->id}}" @if ($childGamme->id === $product->sous_gamme_id) selected @endif>{{$childGamme->title}}</option>
@endif
@endforeach
@endforeach
</select>
</div>
@endif
@include('back.modules.input-error', ['inputName'=>'gamme_id'])
</div>
{{-- LE CONTENU --}}
<div><p class="fs-2 fw-bold">Le contenu</p></div>
@ -82,13 +66,14 @@ $pictos = json_decode($product->pictos);
<td><img src="{{$picto->url}}" alt="{{$picto->name}}" style="max-height: 100px;"></td>
<td>
<div class="form-switch">
<input class="form-check-input" type="checkbox" id="is_activated{{$picto->id}}" name="is_activated{{$picto->id}}" @if (old(`is_activated{{$picto->id}}`, $picto->status) === 1 || old(`is_activated{{$picto->id}}`, $picto->status) === 'on')checked="checked" @endif>
<input class="form-check-input" type="checkbox" id="is_activated{{$picto->id}}" name="is_activated{{$picto->id}}" @if (old(`is_activated{{$picto->id}}` ?? '', $picto->status) === true) checked="checked" @endif>
</div>
</td>
@include('back.modules.input-error', ['inputName'=>'is_activated{{$picto->id}}'])
<td><input type="text" id="time_cook{{$picto->id}}" name="time_cook{{$picto->id}}" class="form-control" placeholder="{{ __('Temps de cuisson') }}" value="{{ old(`time_cook{{$picto->id}}`, $picto->time ?? '') }}"></td>
{{-- <td><input type="text" id="time_cook{{$picto->id}}" name="time_cook{{$picto->id}}" class="form-control" placeholder="{{ __('Temps de cuisson') }}" value="{{ old(`time_cook{{$picto->id}}`, $picto->time ?? '') }}"></td> --}}
<td><input type="text" id="time_cook{{$picto->id}}" name="time_cook{{$picto->id}}" class="form-control" placeholder="{{ __('Temps de cuisson') }}" value="{{ old('time_cook', $picto->time ?? '') }}"></td>
@include('back.modules.input-error', ['inputName'=>'time_cook{{$picto->id}}'])
<td><input type="text" id="temp_cook{{$picto->id}}" name="temp_cook{{$picto->id}}" class="form-control" placeholder="{{ __('Température de cuisson') }}" value="{{ old(`temp_cook{{$picto->id}}`, $picto->temp ?? '') }}"></td>
<td><input type="text" id="temp_cook{{$picto->id}}" name="temp_cook{{$picto->id}}" class="form-control" placeholder="{{ __('Température de cuisson') }}" value="{{ old('temp_cook', $picto->temp ?? '') }}"></td>
@include('back.modules.input-error', ['inputName'=>'temp_cook{{$picto->id}}'])
</tr>
@endforeach
@ -102,7 +87,7 @@ $pictos = json_decode($product->pictos);
$plusproduit = json_decode($product->plusproduit);
@endphp
@if (isset($plusproduit))
<div class="d-flex flex-column form-group mb-3 w-75">
<div class="d-flex flex-column form-group mb-3">
<div><p class="fs-2 fw-bold">Les + produit</p></div>
<div class="d-flex flex-column">
<table class="table bg-light">
@ -115,7 +100,7 @@ $plusproduit = json_decode($product->plusproduit);
<tbody>
@foreach ($plusproduit as $plus)
<tr>
<td><input type="text" id="content{{$plus->id}}" name="content{{$plus->id}}" class="form-control" placeholder="{{ __('Texte') }} *" value="{{ old(`content{{$plus->id}}`, $plus->name ?? '') }}" required></td>
<td><input type="text" id="content{{$plus->id}}" name="content{{$plus->id}}" class="form-control" placeholder="{{ __('Texte') }} *" value="{{ old('content', $plus->name ?? '') }}" required></td>
@include('back.modules.input-error', ['inputName'=>'content{{$plus->id}}'])
<td>
<div class="form-group">
@ -148,8 +133,12 @@ $plusproduit = json_decode($product->plusproduit);
<label class="form-check-label" for="is_on_top">{{ __('A la une') }}</label>
@include('back.modules.input-error', ['inputName'=>'is_on_top'])
</div>
<div class="form-group form-switch mb-3">
<div class="form-group form-switch">
<input class="form-check-input" type="checkbox" id="is_food_service" name="is_food_service" @if (old('is_food_service', $product->is_food_service) === 1 || old('is_food_service', $product->is_food_service) === 'on')checked="checked" @endif>
<label class="form-check-label" for="is_food_service">{{ __('Affiché dans la page "Food Service"') }}</label>
@include('back.modules.input-error', ['inputName'=>'is_food_service'])
</div>
</div><div class="form-group form-switch mb-3">
<input class="form-check-input" type="checkbox" id="is_halal" name="is_halal" @if (old('is_halal', $product->is_halal) === 1 || old('is_halal', $product->is_halal) === 'on')checked="checked" @endif>
<label class="form-check-label" for="is_halal">{{ __('Produit Halal') }}</label>
@include('back.modules.input-error', ['inputName'=>'is_halal'])
</div>

View file

@ -17,10 +17,10 @@
<th scope="col">{{ __('Libellé') }}</th>
<th scope="col">{{ __('Image') }}</th>
<th scope="col">{{ __('Gamme') }}</th>
<th scope="col">{{ __('Sous-gamme') }}</th>
<th scope="col">{{ __('Publié') }}</th>
<th scope="col">{{ __('A la une') }}</th>
<th scope="col">{{ __('Food Service') }}</th>
<th scope="col">{{ __('Halal') }}</th>
<th scope="col"></th>
</tr>
</thead>
@ -36,16 +36,10 @@
@else
<td>-</td>
@endif
@if (isset($product->sousGamme))
<td>
<a href="{{route('bo.gammes.edit', $product->sousGamme->id) }}">{{$product->sousGamme->title}}</a>
</td>
@else
<td>-</td>
@endif
<td>{{$product->is_published}}</td>
<td>{{$product->is_on_top}}</td>
<td>{{$product->is_food_service}}</td>
<td>{{$product->is_published ? 'Oui' : 'Non'}}</td>
<td>{{$product->is_on_top ? 'Oui' : 'Non'}}</td>
<td>{{$product->is_food_service ? 'Oui' : 'Non'}}</td>
<td>{{$product->is_halal ? 'Oui' : 'Non'}}</td>
<td>
<a href="{{route('bo.products.edit', ['product' => $product->id])}}" class="btn btn-sm btn-primary">{{ __('Éditer') }}</a>
<form action="{{route('bo.products.destroy', $product->id)}}" method="POST" class="d-inline">

View file

@ -1,10 +1,13 @@
<div class="is-flex">
{{-- @php
dd($products);
@endphp --}}
@foreach ($products as $product)
@if (isset($childGamme))
@if ($product->sous_gamme_id === $childGamme->id)
@if ($product->gamme_id === $childGamme->id)
@include('front.gammes.product')
@endif
@elseif ($product->gamme_id === $gamme->id && $product->sous_gamme_id === null)
@elseif ($product->gamme_id === $gamme->id)
@include('front.gammes.product')
@endif
@endforeach