feat: ✨ add CRUD product types

This commit is contained in:
Alexis Gousseau 2024-06-10 15:46:50 +02:00
parent a70f082d5d
commit 35fc53e230
22 changed files with 1087 additions and 4 deletions

View file

@ -0,0 +1,187 @@
<?php
namespace App\Http\Controllers\Bo;
use App\Http\Controllers\Controller;
use App\Http\Requests\Bo\ProductTypes\StoreProductTypeRequest;
use App\Http\Requests\Bo\ProductTypes\UpdateProductTypeRequest;
use App\Models\ProductType;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
class ProductTypeController extends Controller
{
/**
* Create the controller instance.
*/
public function __construct()
{
$this->authorizeResource(ProductType::class);
}
/**
* Display a listing of the resource.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Contracts\View\View
*/
public function index(Request $request): \Illuminate\Contracts\View\View
{
/** @var \Illuminate\Database\Eloquent\Builder $productTypeModels */
$productTypeModels = ProductType::query();
/** @var string $search Search field */
$search = $request->search;
if ($search) {
$this->searchQuery(
$productTypeModels,
$search,
null,
'label',
'description',
);
}
$searchFields = \implode(', ', [
trans('validation.custom.label'),
trans('validation.attributes.description'),
]);
/** Sort columns with a query */
$this->sortQuery($productTypeModels);
/** Custom pagination */
$productTypeModels = $this->paginate($productTypeModels);
return view('bo.pages.product_types.index', compact('productTypeModels', 'search', 'searchFields'));
}
/**
* Show the specified resource.
*
* @param \App\Models\ProductType $productType
* @return \Illuminate\Contracts\View\View
*/
public function show(ProductType $productType): \Illuminate\Contracts\View\View
{
return view('bo.pages.product_types.show', ['productTypeModel' => $productType]);
}
/**
* Show the form for creating a new resource.
*
* @param \App\Models\ProductType $productType
* @return \Illuminate\Contracts\View\View
*/
public function create(ProductType $productType): \Illuminate\Contracts\View\View
{
return view('bo.pages.product_types.create', ['productTypeModel' => $productType]);
}
/**
* Store a newly created resource in storage.
*
* @param \App\Http\Requests\Bo\ProductTypes\StoreProductTypeRequest $request
* @return \Illuminate\Http\RedirectResponse
*/
public function store(StoreProductTypeRequest $request): \Illuminate\Http\RedirectResponse
{
return DB::transaction(function () use ($request) {
$productTypeModel = new ProductType();
$productTypeModel->fill($request->validated());
if ($productTypeModel->saveOrFail()) {
return redirect()->route('bo.product_types.edit', $productTypeModel)
->with('success', trans('crud.messages.has_been_created', [
'model' => Str::ucfirst(trans('models.classes.product_type'))
]));
}
return redirect()->back()
->with('error', trans('crud.messages.cannot_be_created', [
'model' => Str::ucfirst(trans('models.classes.product_type'))
]));
});
}
/**
* Show the form for editing the specified resource.
*
* @param \App\Models\ProductType $productType
* @return \Illuminate\Contracts\View\View
*/
public function edit(ProductType $productType): \Illuminate\Contracts\View\View
{
return view('bo.pages.product_types.edit', ['productTypeModel' => $productType]);
}
/**
* Update the specified resource in storage.
*
* @param \App\Http\Requests\Bo\ProductTypes\UpdateProductTypeRequest $request
* @param \App\Models\ProductType $productType
* @return \Illuminate\Http\RedirectResponse
*/
public function update(
UpdateProductTypeRequest $request,
ProductType $productType
): \Illuminate\Http\RedirectResponse {
return DB::transaction(function () use ($request, $productType) {
$productType->fill($request->validated());
if ($productType->saveOrFail()) {
return redirect()->route('bo.product_types.edit', $productType)
->with('success', trans('crud.messages.has_been_updated', [
'model' => Str::ucfirst(trans('models.classes.product_type'))
]));
}
return redirect()->route('bo.product_types.edit', $productType)
->with('error', trans('crud.messages.cannot_be_updated', [
'model' => Str::ucfirst(trans('models.classes.product_type'))
]));
});
}
/**
* Remove the specified resource from storage.
*
* @param \App\Models\ProductType $productType
* @return \Illuminate\Http\RedirectResponse
*/
public function destroy(ProductType $productType): \Illuminate\Http\RedirectResponse
{
/** @var array<string,string> */
$previousQueries = [];
\parse_str(\parse_url(url()->previous(), \PHP_URL_QUERY), $previousQueries);
if ($productType->deleteOrFail()) {
return redirect()->route('bo.product_types.index', $previousQueries)
->with('success', trans('crud.messages.has_been_deleted', [
'model' => Str::ucfirst(trans('models.classes.product_type'))
]));
}
return redirect()->back()
->with('error', trans('crud.messages.cannot_be_deleted', [
'model' => Str::ucfirst(trans('models.classes.product_type'))
]));
}
/**
* Duplicate the specified resource.
*
* @param \App\Models\ProductType $productType
* @return \Illuminate\Contracts\View\View
*/
public function duplicate(ProductType $productType): \Illuminate\Contracts\View\View
{
return $this->create($productType->replicate());
}
/**
* Change model button status.
*
* @param \App\Models\ProductType $productType
* @return \Illuminate\Http\RedirectResponse
*/
public function changeButtonStatus(ProductType $productType)
{
$productType->update(['button_status' => !$productType->getOriginal('button_status')]);
return redirect()->back()->with('success', __('crud.messages.publish_status_saved'));
}
}

View file

@ -192,6 +192,6 @@ class VideoController extends Controller
public function changeHomepage(Video $video): \Illuminate\Http\RedirectResponse
{
$video->update(['is_on_homepage' => !$video->getOriginal('is_on_homepage')]);
return redirect()->back()->with('success', trans(__('crud.messages.publish_status_saved')));
return redirect()->back()->with('success', __('crud.messages.publish_status_saved'));
}
}

View file

@ -0,0 +1,74 @@
<?php
namespace App\Http\Requests\Bo\ProductTypes;
use App\Models\ProductType;
use App\Rules\WysiwygLength;
use App\Traits\Requests\HasPicture;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Gate;
class StoreProductTypeRequest extends FormRequest
{
use HasPicture;
/**
* Determine if the user is authorized to make this request.
*
* @return boolean
*/
public function authorize(): bool
{
return Gate::check('create', ProductType::class);
}
/**
* Prepare the data for validation.
*
* @return void
*/
protected function prepareForValidation(): void
{
$this->merge([
'button_status' => $this->boolean('button_status')
]);
$this->mergePicture('picture');
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules(): array
{
$rules = [
'label' => 'required|string|between:3,255',
'description' => ['required', 'string', new WysiwygLength()],
'picture_alt' => 'required_with:picture|nullable|between:3,255',
'picture_title' => 'required_with:picture|nullable|between:3,255',
'button_status' => 'required|boolean',
];
return \array_merge(
$rules,
$this->pictureRules('picture', 150, 150, 150, 150),
);
}
/**
* Get custom attributes for validator errors.
*
* @return array
*/
public function attributes(): array
{
return [
'label' => trans('validation.custom.label'),
'description' => trans('validation.attributes.description'),
'picture' => trans('validation.attributes.image'),
'picture_alt' => trans('validation.custom.attribute_alt'),
'picture_title' => trans('validation.custom.attribute_title'),
'button_status' => trans('validation.attributes.published')
];
}
}

View file

@ -0,0 +1,18 @@
<?php
namespace App\Http\Requests\Bo\ProductTypes;
use Illuminate\Support\Facades\Gate;
class UpdateProductTypeRequest extends StoreProductTypeRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return boolean
*/
public function authorize(): bool
{
return Gate::check('update', $this->route('product_type'));
}
}

103
app/Models/ProductType.php Normal file
View file

@ -0,0 +1,103 @@
<?php
namespace App\Models;
use App\Lib\Helpers\FileStorageHelper;
use App\Lib\Helpers\ToolboxHelper;
use App\Traits\Models\ActivityLog;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
/**
* @property string $label Product type label.
* @property string $slug Product type slug.
* @property string $description Product type description.
* @property string $picture Product type picture.
* @property string $picture_alt Picture alt attribute.
* @property string $picture_title Picture title attribute.
* @property boolean $button_status Product type order.
* @property-read \Carbon\Carbon $created_at Created date.
* @property-read \Carbon\Carbon $updated_at Updated date.
*
* @property-read \App\Models\Product $products Product polymorphic relationship.
*/
class ProductType extends Model
{
use ActivityLog;
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'label',
'slug',
'description',
'picture',
'picture_alt',
'picture_title',
'button_status',
];
/**
* The attributes that should be cast.
*
* @var array<string, string>
*/
protected $casts = [
'button_status' => 'boolean',
];
/**
* Perform any actions required after the model boots.
*
* @return void
*/
protected static function booted(): void
{
static::creating(function (self $model) {
self::assertLabelIsUnique($model->label);
$model->picture = FileStorageHelper::storeFile($model, $model->picture, true);
});
static::updating(function (self $model) {
self::assertLabelIsUnique($model->label, $model->id);
$model->picture = FileStorageHelper::storeFile($model, $model->picture, true);
});
static::updated(function (self $model) {
FileStorageHelper::removeOldFile($model, 'picture');
});
static::deleted(function (self $model) {
FileStorageHelper::removeFile($model, 'picture');
});
}
// * METHODS
/**
* Asserts using validation that the label is unique
*
* @param string|null $label
* @param integer|null $id
* @return void
* @throws \Illuminate\Validation\ValidationException If a tange label already exists.
*/
private static function assertLabelIsUnique(string|null $label, ?int $id = null): void
{
$table = (new self())->getTable();
ToolboxHelper::assertFieldIsUnique($table, 'label', $label, $id);
}
// * RELATIONSHIPS
/**
* Get all of the products for the product type.
*
* @return \Illuminate\Database\Eloquent\Relations\MorphToMany
*/
public function products(): \Illuminate\Database\Eloquent\Relations\MorphToMany
{
return $this->morphToMany(Product::class, 'productable');
}
}

View file

@ -0,0 +1,86 @@
<?php
namespace App\Policies;
use App\Enums\Users\RoleEnum;
use App\Models\User;
use App\Policies\Rules\UserStaticRules;
class ProductTypePolicy
{
/**
* Determine whether the user can view any models.
*
* @return boolean
*/
public function viewAny(): bool
{
return UserStaticRules::everyOne();
}
/**
* Determine whether the user can view the model.
*
* @param \App\Models\User $authUser
* @return boolean
*/
public function view(User $authUser): bool
{
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
}
/**
* Determine whether the user can create a new model.
*
* @param \App\Models\User $authUser
* @return boolean
*/
public function create(User $authUser): bool
{
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
}
/**
* Determine whether the user can update the model.
*
* @param \App\Models\User $authUser
* @return boolean
*/
public function update(User $authUser): bool
{
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
}
/**
* Determine whether the user can delete the model.
*
* @param \App\Models\User $authUser
* @return boolean
*/
public function delete(User $authUser): bool
{
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
}
/**
* Determine whether the user can duplicate the model.
*
* @param \App\Models\User $authUser
* @return boolean
*/
public function duplicate(User $authUser): bool
{
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
}
/**
* Determine whether the user can publish/unpublish the model.
*
* @param \App\Models\User $authUser
* @return boolean
*/
public function changeButtonStatus(User $authUser): bool
{
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
}
}

View file

@ -20,6 +20,6 @@ trait UpdateModelPublished
public function changePublished(Model $model)
{
$model->update(['published' => !$model->getOriginal('published')]);
return redirect()->back()->with('success', trans(__('crud.messages.publish_status_saved')));
return redirect()->back()->with('success', __('crud.messages.publish_status_saved'));
}
}

View file

@ -0,0 +1,24 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
class ProductTypeFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition()
{
return [
'label' => fake()->words(rand(1, 2), true),
'description' => fake()->sentence(),
'picture_alt' => fake()->sentence(),
'picture_title' => fake()->sentence(),
'button_status' => fake()->boolean(75),
];
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

View file

@ -0,0 +1,44 @@
<?php
use Database\Seeders\Development\ProductTypeSeeder;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up(): void
{
Schema::create('product_types', function (Blueprint $table) {
$table->id();
$table->string('label')->comment('Product type description.');
$table->text('description')->comment('Product type description.');
$table->string('picture')->comment('Product type picture.');
$table->string('picture_alt')->comment('Picture alt attribute.');
$table->string('picture_title')->comment('Picture title attribute.');
$table->boolean('button_status')->comment('Product type button publish status.');
$table->timestamps();
});
// Call seeder.
Artisan::call('db:seed', [
'--class' => ProductTypeSeeder::class,
]);
}
/**
* Run the migrations.
*
* @return void
*/
public function down(): void
{
Schema::dropIfExists('product_types');
}
};

View file

@ -0,0 +1,30 @@
<?php
namespace Database\Seeders\Development;
use App\Lib\Helpers\FileStorageHelper;
use App\Models\ProductType;
use Illuminate\Database\Seeder;
class ProductTypeSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run(): void
{
FileStorageHelper::removeModelFiles(new ProductType());
// @phpstan-ignore-next-line
ProductType::factory(5)->make()->each(function (ProductType $productTypeModel) {
$productTypeModel->picture = FileStorageHelper::storeFile(
$productTypeModel,
new \SplFileInfo(\resource_path(
'../database/factories/assets/product_types/default-picture-150x150.png'
))
);
$productTypeModel->saveQuietly();
});
}
}

View file

@ -11,13 +11,18 @@ return [
'key_number' => 'key number',
'main_slide' => 'main slide',
'demarche_slide' => 'demarche slide',
'approach' => 'approach|approaches',
'hot_news' => 'hot news',
'range' => 'range',
'subrange' => 'subrange',
'approach' => 'approach|approaches',
'meat' => 'meat',
'submeat' => 'submeat',
'label' => 'label',
'demarche' => 'demarche',
'consumption_moment' => 'consumption moment',
'video' => 'video',
'product' => 'product',
'recipe' => 'recipe',
'product_type' => 'product type|product types',
]
];

View file

@ -23,5 +23,6 @@ return [
'video' => 'vidéo',
'product' => 'produit',
'recipe' => 'recette',
'product_type' => 'type de produit|types de produit',
]
];

View file

@ -374,8 +374,23 @@
])></i>
{{ str(__('models.classes.product'))->ucFirst()->plural() }}
</a>
</li> --}}
{{-- PRODUCT TYPES --}}
<li class="py-1">
<a @class([
"dropdown-item",
'fw-bold text-bg-secondary' => request()->routeIs('bo.product_types.*')
]) data-bs-toggle="tooltip"
href="{{ route('bo.product_types.index') }}"
title="{{ __('crud.helpers.update_model', ['model' => trans_choice('models.classes.product_type', 2)]) }}">
<i @class([
"fa-solid fa-drumstick-bite fa-fw",
'fa-lg' => request()->routeIs('bo.product_types.*')
])></i>
{{ str(trans_choice('models.classes.product_type', 2))->ucFirst() }}
</a>
</li>
<li class="py-1"><hr class="dropdown-divider"></li> --}}
<li class="py-1"><hr class="dropdown-divider"></li>
{{-- MEATS --}}
<li class="py-1">
<a @class([

View file

@ -0,0 +1,36 @@
@extends('bo.layout', ['brParam' => $productTypeModel])
@section('title', __('Création d\'une :model', ['model' => trans_choice('models.classes.product_type', 1)]))
@section('description', __('Création d\'une tout nouveau :model', ['model' => trans_choice('models.classes.product_type', 1)]))
@section('breadcrumb', request()->route()->getName())
@section('content')
<div class="d-flex justify-content-between flex-md-nowrap align-items-center flex-wrap pb-3">
<div class="d-flex align-items-start flex-row">
<a class="btn btn-primary text-decoration-none m-0 me-2" data-bs-toggle="tooltip" href="{{ route('bo.product_types.index') }}"
title="{{ __('crud.helpers.list_all', ['model' => trans_choice('models.classes.product_type', 2)]) }}">
<i class="fa-solid fa-arrow-left"></i>
</a>
@include('modules.breadcrumbs.breadcrumb-body', ['brParam' => $productTypeModel])
</div>
<div class="mb-md-0 mb-2">
<button class="btn btn-primary" id="formSubmitClone" data-bs-toggle="tooltip" type="submit"
title="{{ __('crud.helpers.save_model', ['model' => trans_choice('models.classes.product_type', 1)]) }}">
{{ str(__('crud.actions.save'))->ucfirst() }}
</button>
</div>
</div>
<form action="{{ route('bo.product_types.store') }}" method="POST" enctype="multipart/form-data">
@csrf
@include('bo.pages.product_types.form')
@include('bo.partials.script-button-clone')
<div class="row mt-3">
<div class="col text-center">
<button class="btn btn-primary" id="formSubmit" data-bs-toggle="tooltip" type="submit"
title="{{ __('crud.helpers.save_model', ['model' => trans_choice('models.classes.product_type', 1)]) }}">
{{ str(__('crud.actions.save'))->ucfirst() }}
</button>
</div>
</div>
</form>
@endsection

View file

@ -0,0 +1,60 @@
@extends('bo.layout', ['brParam' => $productTypeModel])
@section('title', __('Édition d\'une :model', ['model' => trans_choice('models.classes.product_type', 1)]))
@section('description', __('Édition d\'une :model déjà existant', ['model' => trans_choice('models.classes.product_type', 1)]))
@section('breadcrumb', request()->route()->getName())
@section('content')
<div class="d-flex justify-content-between flex-md-nowrap align-items-center flex-wrap pb-3">
<div class="d-flex align-items-start flex-row">
<a class="btn btn-primary text-decoration-none m-0 me-2" data-bs-toggle="tooltip" href="{{ route('bo.product_types.index') }}"
title="{{ __('crud.helpers.list_all', ['model' => str(trans_choice('models.classes.product_type', 2))->plural()]) }}">
<i class="fa-solid fa-arrow-left"></i>
</a>
@include('modules.breadcrumbs.breadcrumb-body', ['brParam' => $productTypeModel])
</div>
<div class="mb-md-0 mb-2">
<form class="btn-group confirmDeleteTS" action="{{ route('bo.product_types.destroy', $productTypeModel) }}" method="POST" novalidate>
@can('view', $productTypeModel)
<a class="btn btn-warning" data-bs-toggle="tooltip"
href="{{ route('bo.product_types.show', ['product_type' => $productTypeModel]) }}"
title="{{ str(__('crud.actions.show'))->ucfirst() }}">
<i class="fa-solid fa-eye"></i>
</a>
@endcan
@can('duplicate', $productTypeModel)
<a class="btn btn-secondary" data-bs-toggle="tooltip"
href="{{ route('bo.product_types.duplicate', ['product_type' => $productTypeModel]) }}"
title="{{ str(__('crud.actions.duplicate'))->ucfirst() }}">
<i class="fa-solid fa-copy"></i>
</a>
@endcan
<button class="btn btn-primary" id="formSubmitClone" data-bs-toggle="tooltip" type="submit"
title="{{ __('crud.helpers.save_model', ['model' => trans_choice('models.classes.product_type', 1)]) }}">
{{ str(__('crud.actions.save'))->ucfirst() }}
</button>
@can('delete', $productTypeModel)
@csrf
@method('DELETE')
<button class="btn btn-danger" data-bs-toggle="tooltip" type="submit" title="{{ str(__('crud.actions.delete'))->ucfirst() }}">
<i class="fa-solid fa-trash"></i>
</button>
@endcan
</form>
</div>
</div>
<form action="{{ route('bo.product_types.update', $productTypeModel) }}" method="POST" enctype="multipart/form-data">
@csrf
@method('PUT')
@include('bo.pages.product_types.form')
@include('bo.partials.script-button-clone')
<div class="row">
<div class="col text-center">
<button class="btn btn-primary" id="formSubmit" data-bs-toggle="tooltip" type="submit"
title="{{ __('crud.helpers.save_model', ['model' => trans_choice('models.classes.product_type', 1)]) }}">
{{ str(__('crud.actions.save'))->ucfirst() }}
</button>
</div>
</div>
</form>
@endsection

View file

@ -0,0 +1,157 @@
<div class="row">
{{-- LABEL --}}
<div class="col-12 col-lg-6 mb-3">
<fieldset class="h-100 border p-3">
<legend>{{ str(__('validation.custom.label'))->ucFirst() }}</legend>
<div class="row">
<div class="col-12">
@include('bo.partials.inputs.varchar', [
'id' => 'productTypeLabel',
'label' => __(':field :inter:model', [
'field' => str(__('validation.custom.label'))->ucFirst(),
'inter' => __('validation.custom.of_the.male'),
'model' => trans_choice('models.classes.product_type', 1),
]),
'hasWordCounter' => true,
'name' => 'label',
'required' => true,
'model' => $productTypeModel ?? null,
'helper' => __('validation.between.string', [
'attribute' => __(':field :inter:model', [
'field' => __('validation.custom.label'),
'inter' => __('validation.custom.of_the.male'),
'model' => trans_choice('models.classes.product_type', 1),
]),
'min' => 3,
'max' => 255,
]),
'placeholder' => __(':field :inter:model', [
'field' => str(__('validation.custom.label'))->ucFirst(),
'inter' => __('validation.custom.of_the.male'),
'model' => trans_choice('models.classes.product_type', 1),
]),
])
</div>
</div>
</fieldset>
</div>
{{-- DESCRIPTION --}}
<div class="col-12 mb-3">
<fieldset class="border p-3">
<legend>{{ str(__('validation.attributes.description'))->ucfirst() }}</legend>
<div class="row mb-3">
<div class="col-12">
@include('bo.partials.inputs.text-html', [
'id' => 'productTypeDescription',
'label' => str(
__(':field :inter:model', [
'field' => __('validation.attributes.description'),
'inter' => __('validation.custom.of_the.male'),
'model' => trans_choice('models.classes.product_type', 1),
]))->ucfirst(),
'name' => 'description',
'model' => $productTypeModel ?? null,
'required' => true,
'helper' => __('crud.minicrud.text_warning'),
])
</div>
</div>
</fieldset>
</div>
{{-- PICTURE --}}
<div class="col-12 pb-3">
<fieldset class="h-100 border p-3">
<legend>{{ str(__('validation.attributes.image'))->ucFirst() }}</legend>
<div class="row mb-3">
{{-- PICTURE_ALT --}}
<div class="col-12 col-lg-6 m-md-0 mb-3">
@include('bo.partials.inputs.varchar', [
'id' => 'productTypePictureAlt',
'label' => __(':field1 :inter1:field2 :inter2:model', [
'field1' => str(__('validation.custom.attribute_alt'))->ucFirst(),
'inter1' => __('validation.custom.of_the.vowel'),
'field2' => __('validation.attributes.image'),
'inter2' => __('validation.custom.of_the.male'),
'model' => trans_choice('models.classes.product_type', 1),
]),
'hasWordCounter' => true,
'name' => 'picture_alt',
'required' => true,
'model' => $productTypeModel ?? null,
'helper' => __('crud.minicrud.picture_alt_helper'),
'placeholder' => __(':field1 :inter1:field2 :inter2:model', [
'field1' => str(__('validation.custom.attribute_alt'))->ucFirst(),
'inter1' => __('validation.custom.of_the.vowel'),
'field2' => __('validation.attributes.image'),
'inter2' => __('validation.custom.of_the.male'),
'model' => trans_choice('models.classes.product_type', 1),
]),
])
</div>
{{-- PICTURE_TITLE --}}
<div class="col-12 col-lg-6 mb-3">
@include('bo.partials.inputs.varchar', [
'id' => 'productTypePictureTitle',
'label' => __(':field1 :inter1:field2 :inter2:model', [
'field1' => str(__('validation.custom.attribute_title'))->ucFirst(),
'inter1' => __('validation.custom.of_the.vowel'),
'field2' => __('validation.attributes.image'),
'inter2' => __('validation.custom.of_the.male'),
'model' => trans_choice('models.classes.product_type', 1),
]),
'hasWordCounter' => true,
'name' => 'picture_title',
'required' => true,
'model' => $productTypeModel ?? null,
'helper' => __('crud.minicrud.picture_title_helper'),
'placeholder' => __(':field1 :inter1:field2 :inter2:model', [
'field1' => str(__('validation.custom.attribute_title'))->ucFirst(),
'inter1' => __('validation.custom.of_the.vowel'),
'field2' => __('validation.attributes.image'),
'inter2' => __('validation.custom.of_the.male'),
'model' => trans_choice('models.classes.product_type', 1),
]),
])
</div>
{{-- PICTURE --}}
<div class="col-12">
@include('bo.partials.inputs.varchar-picture', [
'id' => 'productTypePicture',
'name' => 'picture',
'width' => 150,
'height' => 150,
'model' => $productTypeModel ?? null,
'required' => true,
'preview' => true,
])
</div>
</div>
</fieldset>
</div>
{{-- BUTTON STATUS --}}
<div class="col-12 col-md-6 mb-3">
@can('changeButtonStatus', $productTypeModel)
<fieldset class="h-100 border p-3">
<legend>{{ __('crud.minicrud.visibility_label') }}</legend>
<div class="row">
<div class="col-12">
@include('bo.partials.inputs.tinyint-boolean', [
'id' => 'productTypeButtonStatus',
'name' => 'button_status',
'model' => $productTypeModel ?? null,
'label' => __('Rendre visible le bouton'),
'helper' => __('crud.minicrud.visibility_helper'),
])
</div>
</div>
</fieldset>
@else
<span class="text-danger" data-bs-toggle="tooltip" title="{{ __('crud.other.right') }}">
<i class="fa-solid fa-ban"></i>
</span>
@endcan
</div>
<div class="col-12 text-center">
<p><b>{{ __('* Champs obligatoires') }}</b></p>
</div>
</div>

View file

@ -0,0 +1,89 @@
<table class="table-hover table-fix-action m-0 table">
@if (count($productTypeModels) > 0)
<thead>
@include('bo.modules.table-col-sorter', [
'cols' => [
'label' => str(__('validation.custom.label'))->ucfirst(),
'description' => str(__('validation.attributes.description'))->ucfirst(),
'button_status' => str(__('validation.custom.button_status'))->ucfirst(),
'updated_at' => str(__('validation.attributes.updated_at'))->ucfirst(),
],
])
</thead>
<tbody>
@foreach ($productTypeModels as $productTypeModel)
<tr class="border-bottom">
<td class="text-center align-middle">{{ $productTypeModel->label }}</td>
<td class="text-center align-middle">{!! clean($productTypeModel->description) !!}</td>
<td class="text-center align-middle">
<form action="{{ route('bo.product_types.change-button-status', $productTypeModel->getRouteKey()) }}" method="POST">
@csrf
@method('PATCH')
<button data-bs-toggle="tooltip" type="submit"
title="{{ __($productTypeModel->button_status ? __('crud.other.publish') : __('crud.other.unpublish')) }}" @class([
'btn btn-sm',
'btn-primary' => $productTypeModel->button_status,
'btn-danger' => !$productTypeModel->button_status,
])>
<i @class([
'fa-solid',
'fa-circle-check' => $productTypeModel->button_status,
'fa-circle-xmark' => !$productTypeModel->button_status,
])></i>
</button>
</form>
</td>
<td class="text-center align-middle">
<span class="badge text-bg-secondary">{{ $productTypeModel->updated_at->isoFormat('LLLL') }}</span>
</td>
<td class="text-end align-middle">
@canAny(['show', 'duplicate', 'update', 'delete'], $productTypeModel)
<form class="btn-group confirmDeleteTS" action="{{ route('bo.product_types.destroy', $productTypeModel) }}"
method="POST" novalidate>
@can('view', $productTypeModel)
<a class="btn btn-sm btn-warning" data-bs-toggle="tooltip"
href="{{ route('bo.product_types.show', ['product_type' => $productTypeModel]) }}"
title="{{ str(__('crud.actions.show'))->ucfirst() }}">
<i class="fa-solid fa-eye"></i>
</a>
@endcan
@can('duplicate', $productTypeModel)
<a class="btn btn-sm btn-secondary" data-bs-toggle="tooltip"
href="{{ route('bo.product_types.duplicate', ['product_type' => $productTypeModel]) }}"
title="{{ str(__('crud.actions.duplicate'))->ucfirst() }}">
<i class="fa-solid fa-copy"></i>
</a>
@endcan
@can('update', $productTypeModel)
<a class="btn btn-sm btn-primary" data-bs-toggle="tooltip"
href="{{ route('bo.product_types.edit', ['product_type' => $productTypeModel]) }}"
title="{{ str(__('crud.actions.update'))->ucfirst() }}">
<i class="fa-solid fa-pencil"></i>
</a>
@endcan
@can('delete', $productTypeModel)
@csrf
@method('DELETE')
<button class="btn btn-sm btn-danger" data-bs-toggle="tooltip" type="submit"
title="{{ str(__('crud.actions.delete'))->ucfirst() }}">
<i class="fa-solid fa-trash"></i>
</button>
@endcan
</form>
@else
<span class="text-danger" data-bs-toggle="tooltip" title="{{ __('list.right') }}">
<i class="fa-solid fa-ban"></i>
</span>
@endcan
</td>
</tr>
@endforeach
</tbody>
@else
<tr>
<td class="border-0">
{{ trans_choice('crud.other.no_model_found', 1, ['model' => trans_choice('models.classes.product_type', 1)]) }}
</td>
</tr>
@endif
</table>

View file

@ -0,0 +1,21 @@
@extends('bo.layout')
@section('title', str(trans_choice('models.classes.product_type', 2))->ucfirst())
@section('description', __('Liste de tous les :model', ['model' => trans_choice('models.classes.product_type', 2)]))
@section('content')
<div class="d-flex justify-content-between flex-md-nowrap align-items-center flex-wrap">
@include('modules.breadcrumbs.breadcrumb-body')
@can('create', \App\Models\ProductType::class)
<a class="btn btn-primary float-right" data-bs-toggle="tooltip" href="{{ route('bo.product_types.create') }}"
title="{{ __('crud.helpers.create_model', ['model' => __('models.classes.product_type')]) }}">
<i class="fa-solid fa-plus"></i>
</a>
@endcan
</div>
@include('bo.modules.search-bar')
<div class="table-responsive mb-3">
@include('bo.pages.product_types.index-list')
</div>
{{ $productTypeModels->links() }}
@endsection

View file

@ -0,0 +1,96 @@
@extends('bo.layout', ['brParam' => $productTypeModel])
@section('title', __('Aperçu d\'une :model', ['model' => trans_choice('models.classes.product_type', 1)]))
@section('description', __('Aperçu d\'une :model déjà existante', ['model' => trans_choice('models.classes.product_type', 1)]))
@section('breadcrumb', request()->route()->getName())
@section('content')
<div class="d-flex justify-content-between flex-md-nowrap align-items-center border-bottom flex-wrap pb-3">
<div class="d-flex align-items-start flex-row">
<a class="btn btn-primary text-decoration-none m-0 me-2" data-bs-toggle="tooltip" data-bs-placement="top"
href="{{ route('bo.product_types.index', ['sort_col' => 'created_at', 'sort_way' => 'desc']) }}"
title="{{ __('crud.helpers.list_all', ['model' => trans_choice('models.classes.product_type', 2)]) }}">
<i class="fa-solid fa-arrow-left"></i>
</a>
@include('modules.breadcrumbs.breadcrumb-body', ['brParam' => $productTypeModel])
</div>
@canAny(['duplicate', 'update', 'delete'], $productTypeModel)
<form class="btn-group confirmActionTS" data-message="{{ __('crud.sweetalert.data_lost') }}"
action="{{ route('bo.product_types.destroy', $productTypeModel) }}" method="POST" novalidate>
@can('duplicate', $productTypeModel)
<a class="btn btn-secondary" data-bs-toggle="tooltip" data-bs-placement="top"
href="{{ route('bo.product_types.duplicate', ['product_type' => $productTypeModel]) }}"
title="{{ __('crud.helpers.duplicate_model', ['model' => trans_choice('models.classes.product_type', 1)]) }}">
<i class="fa-solid fa-copy"></i>
</a>
@endcan
@can('update', $productTypeModel)
<a class="btn btn-primary" data-bs-toggle="tooltip" data-bs-placement="top"
href="{{ route('bo.product_types.edit', ['product_type' => $productTypeModel]) }}"
title="{{ __('crud.helpers.edit_model', ['model' => trans_choice('models.classes.product_type', 1)]) }}">
<i class="fa-solid fa-pencil"></i>
</a>
@endcan
@can('delete', $productTypeModel)
@csrf
@method('DELETE')
<button class="btn btn-danger" data-bs-toggle="tooltip" data-bs-placement="top" type="submit"
title="{{ __('crud.helpers.delete_model', ['model' => trans_choice('models.classes.product_type', 1)]) }}">
<i class="fa-solid fa-trash"></i>
</button>
@endcan
</form>
@endcan
</div>
<div class="row">
<div class="col-12">
<div class="table-responsive mb-3">
<table class="table-hover m-0 table">
<tbody>
<tr class="border-bottom">
<td class="w-50 fw-bold text-center align-middle">{{ str(__('validation.custom.label'))->ucFirst() }}</td>
<td class="w-50 text-center align-middle">
{{ $productTypeModel->label }}
</td>
</tr>
<tr class="border-bottom">
<td class="w-50 fw-bold text-center align-middle">{{ str(__('validation.attributes.description'))->ucFirst() }}</td>
<td class="w-50 text-center align-middle">
{!! clean($productTypeModel->description) !!}
</td>
</tr>
<tr class="border-bottom">
<td class="w-50 fw-bold text-center align-middle">{{ str(__('validation.attributes.image'))->ucFirst() }}</td>
<td class="w-50 text-center align-middle">
<img class="img-fluid" src="{{ asset($productTypeModel->picture) }}"
title="{{ $productTypeModel->picture_title }}" alt="{{ $productTypeModel->picture_alt }}">
</td>
</tr>
<tr class="border-bottom">
<td class="w-50 fw-bold text-center align-middle">
{{ str(__('validation.custom.publication'))->ucFirst() }}
</td>
<td class="w-50 text-center align-middle">
{{ $productTypeModel->button_status
? str($productTypeModel->created_at->isoFormat('LLLL'))->ucFirst()
: __('crud.other.model_not_published') }}
</td>
</tr>
<tr class="border-bottom">
<td class="w-50 fw-bold text-center align-middle">{{ str(__('validation.attributes.created_at'))->ucFirst() }}</td>
<td class="w-50 text-center align-middle">
{{ str($productTypeModel->created_at->isoFormat('LLLL'))->ucFirst() }}
</td>
</tr>
<tr class="border-bottom">
<td class="w-50 fw-bold text-center align-middle">{{ str(__('validation.attributes.updated_at'))->ucFirst() }}</td>
<td class="w-50 text-center align-middle">
{{ str($productTypeModel->updated_at->isoFormat('LLLL'))->ucFirst() }}
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
@endsection

View file

@ -11,6 +11,7 @@ use App\Models\ConsumptionMoment;
use App\Models\MainSlide;
use App\Models\GeneralSetting;
use App\Models\Meat;
use App\Models\ProductType;
use App\Models\Range;
use App\Models\Recipe;
use App\Models\StaticPage;
@ -302,6 +303,30 @@ Breadcrumbs::for('bo.submeats.duplicate', function (Generator $trail) {
$trail->push(Str::ucfirst(trans('crud.actions.duplicate')));
});
// * PRODUCT TYPES
Breadcrumbs::for('bo.product_types.index', function (Generator $trail) {
$trail->push(
Str::of(trans_choice('models.classes.product_type', 2))->ucfirst(),
route('bo.product_types.index')
);
});
Breadcrumbs::for('bo.product_types.show', function (Generator $trail, ProductType $productType) {
$trail->parent('bo.product_types.index');
$trail->push(Str::ucfirst(trans('crud.actions.view')), route('bo.product_types.show', $productType));
});
Breadcrumbs::for('bo.product_types.create', function (Generator $trail) {
$trail->parent('bo.product_types.index');
$trail->push(Str::ucfirst(trans('crud.actions.create')), route('bo.product_types.create'));
});
Breadcrumbs::for('bo.product_types.edit', function (Generator $trail, ProductType $productType) {
$trail->parent('bo.product_types.index');
$trail->push(Str::ucfirst(trans('crud.actions.edit')), route('bo.product_types.edit', $productType));
});
Breadcrumbs::for('bo.product_types.duplicate', function (Generator $trail) {
$trail->parent('bo.product_types.index');
$trail->push(Str::ucfirst(trans('crud.actions.duplicate')));
});
// * APPROACHES
Breadcrumbs::for('bo.approaches.index', function (Generator $trail, int $approach_type) {
$trail->push(

View file

@ -12,6 +12,7 @@ use App\Http\Controllers\Bo\MainSlideController;
use App\Http\Controllers\Bo\MenuNodeDataController;
use App\Http\Controllers\Bo\MeatController;
use App\Http\Controllers\Bo\ProductController;
use App\Http\Controllers\Bo\ProductTypeController;
use App\Http\Controllers\Bo\ProfessionController;
use App\Http\Controllers\Bo\RangeController;
use App\Http\Controllers\Bo\RecipeController;
@ -205,6 +206,17 @@ Route::prefix('bo')
SubmeatController::class, 'duplicate'
])->name('submeats.duplicate');
// * PRODUCT TYPES.
Route::resource('product_types', ProductTypeController::class)
->withoutMiddleware('htmlsanitize')
->middleware('htmlsanitize:description');
Route::patch('/product_types/{product_type}/change-button-status', [
ProductTypeController::class, 'changeButtonStatus'
])->name('product_types.change-button-status');
Route::get('/product_types/{product_type}/duplicate', [
ProductTypeController::class, 'duplicate'
])->name('product_types.duplicate');
// * APPROACHES.
Route::get('/approaches/{approach_type}', [
ApproachController::class, 'index'