Merge branch 'crud-offers' into le-gaulois-2024

This commit is contained in:
Alexis Gousseau 2024-07-15 10:26:21 +02:00
commit 10eb7bc0aa
25 changed files with 1186 additions and 6 deletions

View file

@ -0,0 +1,176 @@
<?php
namespace App\Http\Controllers\Bo;
use App\Http\Controllers\Controller;
use App\Http\Requests\Bo\Offers\StoreOfferRequest;
use App\Http\Requests\Bo\Offers\UpdateOfferRequest;
use App\Models\Offer;
use App\Traits\Controllers\UpdateModelPublished;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
class OfferController extends Controller
{
use UpdateModelPublished;
/**
* Create the controller instance.
*/
public function __construct()
{
$this->authorizeResource(Offer::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 $offerModels */
$offerModels = Offer::query();
/** @var string $search Search field */
$search = $request->search;
if ($search) {
$this->searchQuery(
$offerModels,
$search,
null,
'label',
);
}
$searchFields = \implode(', ', [
trans('validation.custom.label'),
]);
/** Sort columns with a query */
$this->sortQuery($offerModels);
/** Custom pagination */
$offerModels = $this->paginate($offerModels);
return view('bo.pages.offers.index', compact('offerModels', 'search', 'searchFields'));
}
/**
* Show the specified resource.
*
* @param \App\Models\Offer $offer
* @return \Illuminate\Contracts\View\View
*/
public function show(Offer $offer): \Illuminate\Contracts\View\View
{
return view('bo.pages.offers.show', ['offerModel' => $offer]);
}
/**
* Show the form for creating a new resource.
*
* @param \App\Models\Offer $offer
* @return \Illuminate\Contracts\View\View
*/
public function create(Offer $offer): \Illuminate\Contracts\View\View
{
return view('bo.pages.offers.create', ['offerModel' => $offer]);
}
/**
* Store a newly created resource in storage.
*
* @param \App\Http\Requests\Bo\Offers\StoreOfferRequest $request
* @return \Illuminate\Http\RedirectResponse
*/
public function store(StoreOfferRequest $request): \Illuminate\Http\RedirectResponse
{
return DB::transaction(function () use ($request) {
$offer = new Offer();
$offer->fill($request->validated());
if ($offer->saveOrFail()) {
return redirect()->route('bo.offers.edit', $offer)
->with('success', trans('crud.messages.has_been_created', [
'model' => Str::ucfirst(trans('models.classes.offer'))
]));
}
return redirect()->back()
->with('error', trans('crud.messages.cannot_be_created', [
'model' => Str::ucfirst(trans('models.classes.offer'))
]));
});
}
/**
* Show the form for editing the specified resource.
*
* @param \App\Models\Offer $offer
* @return \Illuminate\Contracts\View\View
*/
public function edit(Offer $offer): \Illuminate\Contracts\View\View
{
return view('bo.pages.offers.edit', ['offerModel' => $offer]);
}
/**
* Update the specified resource in storage.
*
* @param \App\Http\Requests\Bo\Offers\UpdateOfferRequest $request
* @param \App\Models\Offer $offer
* @return \Illuminate\Http\RedirectResponse
*/
public function update(UpdateOfferRequest $request, Offer $offer): \Illuminate\Http\RedirectResponse
{
return DB::transaction(function () use ($request, $offer) {
$offer->fill($request->validated());
if ($offer->saveOrFail()) {
return redirect()->route('bo.offers.edit', $offer)
->with('success', trans('crud.messages.has_been_updated', [
'model' => Str::ucfirst(trans('models.classes.offer'))
]));
}
return redirect()->route('bo.offers.edit', $offer)
->with('error', trans('crud.messages.cannot_be_updated', [
'model' => Str::ucfirst(trans('models.classes.offer'))
]));
});
}
/**
* Remove the specified resource from storage.
*
* @param \App\Models\Offer $offer
* @return \Illuminate\Http\RedirectResponse
*/
public function destroy(Offer $offer): \Illuminate\Http\RedirectResponse
{
/** @var array<string,string> */
$previousQueries = [];
\parse_str(\parse_url(url()->previous(), \PHP_URL_QUERY), $previousQueries);
if ($offer->deleteOrFail()) {
return redirect()->route('bo.offers.index', $previousQueries)
->with('success', trans('crud.messages.has_been_deleted', [
'model' => Str::ucfirst(trans('models.classes.offer'))
]));
}
return redirect()->back()
->with('error', trans('crud.messages.cannot_be_deleted', [
'model' => Str::ucfirst(trans('models.classes.offer'))
]));
}
/**
* Duplicate the specified resource.
*
* @param \App\Models\Offer $offer
* @return \Illuminate\Contracts\View\View
*/
public function duplicate(Offer $offer): \Illuminate\Contracts\View\View
{
return $this->create($offer->replicate());
}
}

View file

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

View file

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

76
app/Models/Offer.php Normal file
View file

@ -0,0 +1,76 @@
<?php
namespace App\Models;
use App\Lib\Helpers\FileStorageHelper;
use App\Traits\Models\ActivityLog;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
/**
* @property string $title Offer title.
* @property string $location Offer location.
* @property string $contract Offer contract.
* @property string $function Offer function.
* @property string $picture Offer picture.
* @property string $picture_alt Picture alt attribute.
* @property string $picture_title Picture title attribute.
* @property string $description Offer description.
* @property boolean $published Offer publish status.
* @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 Offer extends Model
{
use ActivityLog;
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'title',
'location',
'contract',
'function',
'picture',
'picture_alt',
'picture_title',
'description',
'published',
];
/**
* The attributes that should be cast.
*
* @var array<string, string>
*/
protected $casts = [
'published' => 'boolean',
];
/**
* Perform any actions required after the model boots.
*
* @return void
*/
protected static function booted(): void
{
static::creating(function (self $offer) {
$offer->picture = FileStorageHelper::storeFile($offer, $offer->picture, true);
});
static::updating(function (self $offer) {
$offer->picture = FileStorageHelper::storeFile($offer, $offer->picture, true);
});
static::updated(function (self $offer) {
FileStorageHelper::removeOldFile($offer, 'picture');
});
static::deleted(function (self $offer) {
FileStorageHelper::removeFile($offer, 'picture');
});
}
}

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 OfferPolicy
{
/**
* 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 changePublished(User $authUser): bool
{
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
}
}

View file

@ -11,6 +11,7 @@ use App\Models\Claim;
use App\Models\ConsumptionMoment;
use App\Models\MainSlide;
use App\Models\Meat;
use App\Models\Offer;
use App\Models\Product;
use App\Models\ProductType;
use App\Models\Range;
@ -78,6 +79,7 @@ class RouteServiceProvider extends ServiceProvider
Route::model('claim', Claim::class);
Route::model('product', Product::class);
Route::model('product_type', ProductType::class);
Route::model('offer', Offer::class);
}
/**

View file

@ -0,0 +1,27 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
class OfferFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition()
{
return [
'title' => fake()->words(3, true),
'location' => fake()->words(5, true),
'contract' => fake()->words(5, true),
'function' => fake()->words(5, true),
'picture_alt' => fake()->words(5, true),
'picture_title' => fake()->words(5, true),
'description' => fake()->sentence(),
'published' => fake()->boolean(75),
];
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

View file

@ -26,7 +26,7 @@ return new class extends Migration
$table->string('picture_alt')->nullable()->comment('Picture alt attribute.')->change();
$table->string('picture_title')->nullable()->comment('Picture title attribute.')->change();
$table->text('content')->nullable()->comment('Static page content.')->change();
$table->mediumText('data')->nullable()->after('content')->comment('Static page content.');
$table->mediumText('data')->nullable()->after('content')->comment('Static page data.');
});
// SAGA.

View file

@ -0,0 +1,47 @@
<?php
use Database\Seeders\Development\OfferSeeder;
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('offers', function (Blueprint $table) {
$table->id();
$table->string('title')->comment('Offer title.');
$table->string('location')->comment('Offer location.');
$table->string('contract')->comment('Offer contract.');
$table->string('function')->comment('Offer function.');
$table->string('picture')->comment('Offer picture.');
$table->string('picture_alt')->comment('Picture alt attribute.');
$table->string('picture_title')->comment('Picture title attribute.');
$table->text('description')->comment('Offer description.');
$table->boolean('published')->comment('Offer publish status.');
$table->timestamps();
});
// Call seeder.
Artisan::call('db:seed', [
'--class' => OfferSeeder::class,
]);
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down(): void
{
Schema::dropIfExists('offers');
}
};

View file

@ -0,0 +1,29 @@
<?php
namespace Database\Seeders\Development;
use App\Lib\Helpers\FileStorageHelper;
use App\Models\Offer;
use Illuminate\Database\Seeder;
class OfferSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run(): void
{
FileStorageHelper::removeModelFiles(new Offer());
Offer::factory(10)->make()->each(function (Offer $offer) {
$offer->picture = FileStorageHelper::storeFile(
$offer,
new \SplFileInfo(\resource_path(
'../database/factories/assets/offers/default-picture-300x200.png'
))
);
$offer->saveQuietly();
});
}
}

View file

@ -25,5 +25,6 @@ return [
'recipe' => 'recipe',
'product_type' => 'product type|product types',
'claim' => 'claim',
'offer' => 'offer',
]
];

View file

@ -245,11 +245,13 @@ return [
'claim' => 'claim',
'color_block' => 'color block',
'color' => 'color',
'contract' => 'contract',
'cooking_time' => 'cooking time (in minutes)',
'demarche' => 'demarche',
'details' => 'details',
'difficulty' => 'difficulty',
'event' => 'event',
'function' => 'function',
'general_setting_type' => 'general setting type',
'highlight' => 'highlight',
'ingredient' => 'ingredient',
@ -258,6 +260,7 @@ return [
'job' => 'job',
'jobs_list' => 'jobs list',
'label' => 'label',
'location' => 'location',
'menu' => 'menu',
'model' => 'model',
'nb_guests' => 'number of reference persons for the list of ingredients',
@ -271,8 +274,8 @@ return [
'product_id' => 'product ID',
'publication' => 'publication',
'publish_at' => 'publish at',
'published' => 'published',
'published_at' => 'published at',
'published' => 'published',
'route_name' => 'name of the route',
'seo_description' => 'seo description',
'seo_title' => 'seo title',

View file

@ -25,5 +25,6 @@ return [
'recipe' => 'recette',
'product_type' => 'type de produit|types de produit',
'claim' => 'allégations',
'offer' => 'offre',
]
];

View file

@ -247,11 +247,13 @@ return [
'claim' => 'allégation',
'color_block' => 'couleur du block',
'color' => 'couleur',
'contract' => 'contrat',
'cooking_time' => 'temps de cuisson (en minutes)',
'demarche' => 'démarche',
'details' => 'détails',
'difficulty' => 'difficulté',
'event' => 'évènement',
'function' => 'fonction',
'general_setting_type' => 'type de configuration',
'highlight' => 'mise en avant',
'ingredient' => 'ingrédient',
@ -260,6 +262,7 @@ return [
'job' => 'offre',
'jobs_list' => 'liste d\'offres',
'label' => 'label',
'location' => 'lieu',
'menu' => 'menu',
'model' => 'élément ciblé',
'nb_guests' => 'nombre de personnes de référence pour la liste des ingrédients',
@ -273,8 +276,8 @@ return [
'product_id' => 'ID du produit',
'publication' => 'publication',
'publish_at' => 'date de publication',
'published' => 'publié',
'published_at' => 'publié le',
'published' => 'publié',
'route_name' => 'nom de la route',
'seo_description' => 'description SEO',
'seo_title' => 'titre SEO',

View file

@ -75,7 +75,8 @@ import {
faList,
faHandPointUp,
faFolderTree,
faClockRotateLeft
faClockRotateLeft,
faHandshake
} from "@fortawesome/free-solid-svg-icons";
config.autoReplaceSvg = false;
@ -155,5 +156,6 @@ library.add(faList);
library.add(faFolderTree);
library.add(faHandPointUp);
library.add(faClockRotateLeft);
library.add(faHandshake);
dom.watch();

View file

@ -237,14 +237,16 @@
'fw-bold active' =>
url()->current() === route('bo.static_pages.edit', $recruitmentStaticPageModel->type->value())
|| request()->routeIs('bo.professions.*')
|| request()->routeIs('bo.brand_advantages.*'),
|| request()->routeIs('bo.brand_advantages.*')
|| request()->routeIs('bo.offers.*'),
])>
<i @class([
'fa-solid fa-briefcase fa-fw',
'fa-lg' =>
url()->current() === route('bo.static_pages.edit', $recruitmentStaticPageModel->type->value())
|| request()->routeIs('bo.professions.*')
|| request()->routeIs('bo.brand_advantages.*'),
|| request()->routeIs('bo.brand_advantages.*')
|| request()->routeIs('bo.offers.*'),
])></i>
&nbsp;{{ __('Recrutement') }}
</button>
@ -281,6 +283,21 @@
{{ str(__('models.classes.profession'))->ucFirst()->plural() }}
</a>
</li>
{{-- OFFERS --}}
<li>
<a @class([
'dropdown-item px-3 py-2',
'fw-bold text-bg-secondary' => request()->routeIs('bo.offers.*'),
]) data-bs-toggle="tooltip"
href="{{ route('bo.offers.index') }}"
title="{{ __('crud.helpers.update_model', ['model' => __('models.classes.offer')]) }}">
<i @class([
'fa-solid fa-handshake me-1 fa-fw',
'fa-lg' => request()->routeIs('bo.offers.*'),
])></i>
{{ str(__('models.classes.offer'))->ucFirst()->plural() }}
</a>
</li>
{{-- BRAND ADVANTAGES --}}
<li>
<a @class([

View file

@ -0,0 +1,36 @@
@extends('bo.layout', ['brParam' => $offerModel])
@section('title', __('Création d\'une :model', ['model' => __('models.classes.offer')]))
@section('description', __('Création d\'une tout nouveau :model', ['model' => __('models.classes.offer')]))
@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.offers.index') }}"
title="{{ __('crud.helpers.list_all', ['model' => __('models.classes.offer')]) }}">
<i class="fa-solid fa-arrow-left"></i>
</a>
@include('modules.breadcrumbs.breadcrumb-body', ['brParam' => $offerModel])
</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' => __('models.classes.offer')]) }}">
{{ str(__('crud.actions.save'))->ucfirst() }}
</button>
</div>
</div>
<form action="{{ route('bo.offers.store') }}" method="POST" enctype="multipart/form-data">
@csrf
@include('bo.pages.offers.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' => __('models.classes.offer')]) }}">
{{ str(__('crud.actions.save'))->ucfirst() }}
</button>
</div>
</div>
</form>
@endsection

View file

@ -0,0 +1,60 @@
@extends('bo.layout', ['brParam' => $offerModel])
@section('title', __('Édition d\'une :model', ['model' => __('models.classes.offer')]))
@section('description', __('Édition d\'une :model déjà existant', ['model' => __('models.classes.offer')]))
@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.offers.index') }}"
title="{{ __('crud.helpers.list_all', ['model' => str(__('models.classes.offer'))->plural()]) }}">
<i class="fa-solid fa-arrow-left"></i>
</a>
@include('modules.breadcrumbs.breadcrumb-body', ['brParam' => $offerModel])
</div>
<div class="mb-md-0 mb-2">
<form class="btn-group confirmDeleteTS" action="{{ route('bo.offers.destroy', $offerModel) }}" method="POST" novalidate>
@can('view', $offerModel)
<a class="btn btn-warning" data-bs-toggle="tooltip"
href="{{ route('bo.offers.show', ['offer' => $offerModel]) }}"
title="{{ str(__('crud.actions.show'))->ucfirst() }}">
<i class="fa-solid fa-eye"></i>
</a>
@endcan
@can('duplicate', $offerModel)
<a class="btn btn-secondary" data-bs-toggle="tooltip"
href="{{ route('bo.offers.duplicate', ['offer' => $offerModel]) }}"
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' => __('models.classes.offer')]) }}">
{{ str(__('crud.actions.save'))->ucfirst() }}
</button>
@can('delete', $offerModel)
@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.offers.update', $offerModel) }}" method="POST" enctype="multipart/form-data">
@csrf
@method('PUT')
@include('bo.pages.offers.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' => __('models.classes.offer')]) }}">
{{ str(__('crud.actions.save'))->ucfirst() }}
</button>
</div>
</div>
</form>
@endsection

View file

@ -0,0 +1,259 @@
<div class="row">
{{-- TITLE --}}
<div class="col-12 col-lg-6 mb-3">
<fieldset class="h-100 border p-3">
<legend>{{ str(__('validation.attributes.title'))->ucFirst() }}</legend>
<div class="row">
<div class="col-12">
@include('bo.partials.inputs.varchar', [
'id' => 'offerTitle',
'label' => __(':field :inter:model', [
'field' => str(__('validation.attributes.title'))->ucFirst(),
'inter' => __('validation.custom.of_the.vowel'),
'model' => __('models.classes.offer'),
]),
'hasWordCounter' => true,
'name' => 'title',
'required' => true,
'model' => $offerModel ?? null,
'helper' => __('validation.between.string', [
'attribute' => __(':field :inter:model', [
'field' => __('validation.attributes.title'),
'inter' => __('validation.custom.of_the.vowel'),
'model' => __('models.classes.offer'),
]),
'min' => 3,
'max' => 255,
]),
'placeholder' => __(':field :inter:model', [
'field' => str(__('validation.attributes.title'))->ucFirst(),
'inter' => __('validation.custom.of_the.vowel'),
'model' => __('models.classes.offer'),
]),
])
</div>
</div>
</fieldset>
</div>
{{-- LOCATION --}}
<div class="col-12 col-lg-6 mb-3">
<fieldset class="h-100 border p-3">
<legend>{{ str(__('validation.custom.location'))->ucFirst() }}</legend>
<div class="row">
<div class="col-12">
@include('bo.partials.inputs.varchar', [
'id' => 'offerLocation',
'label' => __(':field :inter:model', [
'field' => str(__('validation.custom.location'))->ucFirst(),
'inter' => __('validation.custom.of_the.vowel'),
'model' => __('models.classes.offer'),
]),
'hasWordCounter' => true,
'name' => 'location',
'required' => true,
'model' => $offerModel ?? null,
'helper' => __('validation.between.string', [
'attribute' => __(':field :inter:model', [
'field' => __('validation.custom.location'),
'inter' => __('validation.custom.of_the.vowel'),
'model' => __('models.classes.offer'),
]),
'min' => 3,
'max' => 255,
]),
'placeholder' => __(':field :inter:model', [
'field' => str(__('validation.custom.location'))->ucFirst(),
'inter' => __('validation.custom.of_the.vowel'),
'model' => __('models.classes.offer'),
]),
])
</div>
</div>
</fieldset>
</div>
{{-- CONTRACT --}}
<div class="col-12 col-lg-6 mb-3">
<fieldset class="h-100 border p-3">
<legend>{{ str(__('validation.custom.contract'))->ucFirst() }}</legend>
<div class="row">
<div class="col-12">
@include('bo.partials.inputs.varchar', [
'id' => 'offerContract',
'label' => __(':field :inter:model', [
'field' => str(__('validation.custom.contract'))->ucFirst(),
'inter' => __('validation.custom.of_the.vowel'),
'model' => __('models.classes.offer'),
]),
'hasWordCounter' => true,
'name' => 'contract',
'required' => true,
'model' => $offerModel ?? null,
'helper' => __('validation.between.string', [
'attribute' => __(':field :inter:model', [
'field' => __('validation.custom.contract'),
'inter' => __('validation.custom.of_the.vowel'),
'model' => __('models.classes.offer'),
]),
'min' => 3,
'max' => 255,
]),
'placeholder' => __(':field :inter:model', [
'field' => str(__('validation.custom.contract'))->ucFirst(),
'inter' => __('validation.custom.of_the.vowel'),
'model' => __('models.classes.offer'),
]),
])
</div>
</div>
</fieldset>
</div>
{{-- FUNCTION --}}
<div class="col-12 col-lg-6 mb-3">
<fieldset class="h-100 border p-3">
<legend>{{ str(__('validation.custom.function'))->ucFirst() }}</legend>
<div class="row">
<div class="col-12">
@include('bo.partials.inputs.varchar', [
'id' => 'offerFunction',
'label' => __(':field :inter:model', [
'field' => str(__('validation.custom.function'))->ucFirst(),
'inter' => __('validation.custom.of_the.vowel'),
'model' => __('models.classes.offer'),
]),
'hasWordCounter' => true,
'name' => 'function',
'required' => true,
'model' => $offerModel ?? null,
'helper' => __('validation.between.string', [
'attribute' => __(':field :inter:model', [
'field' => __('validation.custom.function'),
'inter' => __('validation.custom.of_the.vowel'),
'model' => __('models.classes.offer'),
]),
'min' => 3,
'max' => 255,
]),
'placeholder' => __(':field :inter:model', [
'field' => str(__('validation.custom.function'))->ucFirst(),
'inter' => __('validation.custom.of_the.vowel'),
'model' => __('models.classes.offer'),
]),
])
</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' => 'offerPictureAlt',
'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' => __('models.classes.offer'),
]),
'hasWordCounter' => true,
'name' => 'picture_alt',
'required' => false,
'model' => $offerModel ?? 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' => __('models.classes.offer'),
]),
])
</div>
{{-- PICTURE_TITLE --}}
<div class="col-12 col-lg-6 mb-3">
@include('bo.partials.inputs.varchar', [
'id' => 'offerPictureTitle',
'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' => __('models.classes.offer'),
]),
'hasWordCounter' => true,
'name' => 'picture_title',
'required' => false,
'model' => $offerModel ?? 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' => __('models.classes.offer'),
]),
])
</div>
{{-- PICTURE --}}
<div class="col-12">
@include('bo.partials.inputs.varchar-picture', [
'id' => 'offerPicture',
'name' => 'picture',
'width' => 300,
'height' => 200,
'model' => $offerModel ?? null,
'required' => true,
'preview' => true,
])
</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' => 'offerDescription',
'label' => str(
__(':field :inter:model', [
'field' => __('validation.attributes.description'),
'inter' => __('validation.custom.of_the.vowel'),
'model' => __('models.classes.offer'),
]))->ucfirst(),
'name' => 'description',
'model' => $offerModel ?? null,
'required' => true,
'helper' => __('crud.minicrud.text_warning'),
])
</div>
</div>
</fieldset>
</div>
{{-- PUBLISHED --}}
<div class="col-12 col-md-6 mb-3">
<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' => 'offerPublished',
'name' => 'published',
'model' => $offerModel ?? null,
'label' => __('crud.minicrud.visibility_label'),
'helper' => __('crud.minicrud.visibility_helper'),
])
</div>
</div>
</fieldset>
</div>
<div class="col-12 text-center">
<p><b>{{ __('* Champs obligatoires') }}</b></p>
</div>
</div>

View file

@ -0,0 +1,84 @@
<table class="table-hover table-fix-action m-0 table">
@if (count($offerModels) > 0)
<thead>
@include('bo.modules.table-col-sorter', [
'cols' => [
'title' => str(__('validation.attributes.title'))->ucfirst(),
'location' => str(__('validation.custom.location'))->ucfirst(),
'contract' => str(__('validation.custom.contract'))->ucfirst(),
'function' => str(__('validation.custom.function'))->ucfirst(),
'picture' => str(__('validation.attributes.image'))->ucfirst(),
'published' => str(__('validation.custom.publication'))->ucfirst(),
'updated_at' => str(__('validation.attributes.updated_at'))->ucfirst(),
],
])
</thead>
<tbody>
@foreach ($offerModels as $offerModel)
<tr class="border-bottom">
<td class="text-center align-middle">{{ $offerModel->title }}</td>
<td class="text-center align-middle">{{ $offerModel->location }}</td>
<td class="text-center align-middle">{{ $offerModel->contract }}</td>
<td class="text-center align-middle">{{ $offerModel->function }}</td>
<td class="text-center align-middle">
<img class="image-preview" src="{{ asset($offerModel->picture) }}" title="{{ $offerModel->picture_title }}"
alt="{{ $offerModel->picture_alt }}">
</td>
@include('bo.modules.change-published-status', [
'routeName' => 'offers',
'model' => $offerModel,
])
<td class="text-center align-middle">
<span class="badge text-bg-secondary">{{ $offerModel->updated_at->isoFormat('LLLL') }}</span>
</td>
<td class="text-end align-middle">
@canAny(['show', 'duplicate', 'update', 'delete'], $offerModel)
<form class="btn-group confirmDeleteTS" action="{{ route('bo.offers.destroy', $offerModel) }}"
method="POST" novalidate>
@can('view', $offerModel)
<a class="btn btn-sm btn-warning" data-bs-toggle="tooltip"
href="{{ route('bo.offers.show', ['offer' => $offerModel]) }}"
title="{{ str(__('crud.actions.show'))->ucfirst() }}">
<i class="fa-solid fa-eye"></i>
</a>
@endcan
@can('duplicate', $offerModel)
<a class="btn btn-sm btn-secondary" data-bs-toggle="tooltip"
href="{{ route('bo.offers.duplicate', ['offer' => $offerModel]) }}"
title="{{ str(__('crud.actions.duplicate'))->ucfirst() }}">
<i class="fa-solid fa-copy"></i>
</a>
@endcan
@can('update', $offerModel)
<a class="btn btn-sm btn-primary" data-bs-toggle="tooltip"
href="{{ route('bo.offers.edit', ['offer' => $offerModel]) }}"
title="{{ str(__('crud.actions.update'))->ucfirst() }}">
<i class="fa-solid fa-pencil"></i>
</a>
@endcan
@can('delete', $offerModel)
@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' => __('models.classes.offer')]) }}
</td>
</tr>
@endif
</table>

View file

@ -0,0 +1,21 @@
@extends('bo.layout')
@section('title', str(__('models.classes.offer'))->ucfirst()->plural())
@section('description', __('Liste de tous les :model', ['model' => str(__('models.classes.offer'))->plural()]))
@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\Offer::class)
<a class="btn btn-primary float-right" data-bs-toggle="tooltip" href="{{ route('bo.offers.create') }}"
title="{{ __('crud.helpers.create_model', ['model' => __('models.classes.offer')]) }}">
<i class="fa-solid fa-plus"></i>
</a>
@endcan
</div>
@include('bo.modules.search-bar')
<div class="table-responsive mb-3">
@include('bo.pages.offers.index-list')
</div>
{{ $offerModels->links() }}
@endsection

View file

@ -0,0 +1,112 @@
@extends('bo.layout', ['brParam' => $offerModel])
@section('title', __('Aperçu d\'une :model', ['model' => __('models.classes.offer')]))
@section('description', __('Aperçu d\'une :model déjà existante', ['model' => __('models.classes.offer')]))
@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.offers.index', ['sort_col' => 'created_at', 'sort_way' => 'desc']) }}"
title="{{ __('crud.helpers.list_all', ['model' => str(__('models.classes.offer'))->plural()]) }}">
<i class="fa-solid fa-arrow-left"></i>
</a>
@include('modules.breadcrumbs.breadcrumb-body', ['brParam' => $offerModel])
</div>
@canAny(['duplicate', 'update', 'delete'], $offerModel)
<form class="btn-group confirmDeleteTS" data-message="{{ __('crud.sweetalert.data_lost') }}"
action="{{ route('bo.offers.destroy', $offerModel) }}" method="POST" novalidate>
@can('duplicate', $offerModel)
<a class="btn btn-secondary" data-bs-toggle="tooltip" data-bs-placement="top"
href="{{ route('bo.offers.duplicate', ['offer' => $offerModel]) }}"
title="{{ __('crud.helpers.duplicate_model', ['model' => __('models.classes.offer')]) }}">
<i class="fa-solid fa-copy"></i>
</a>
@endcan
@can('update', $offerModel)
<a class="btn btn-primary" data-bs-toggle="tooltip" data-bs-placement="top"
href="{{ route('bo.offers.edit', ['offer' => $offerModel]) }}"
title="{{ __('crud.helpers.edit_model', ['model' => __('models.classes.offer')]) }}">
<i class="fa-solid fa-pencil"></i>
</a>
@endcan
@can('delete', $offerModel)
@csrf
@method('DELETE')
<button class="btn btn-danger" data-bs-toggle="tooltip" data-bs-placement="top" type="submit"
title="{{ __('crud.helpers.delete_model', ['model' => __('models.classes.offer')]) }}">
<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.attributes.title'))->ucFirst() }}</td>
<td class="w-50 text-center align-middle">
{{ $offerModel->title }}
</td>
</tr>
<tr class="border-bottom">
<td class="w-50 fw-bold text-center align-middle">{{ str(__('validation.custom.location'))->ucFirst() }}</td>
<td class="w-50 text-center align-middle">
{{ $offerModel->location }}
</td>
</tr>
<tr class="border-bottom">
<td class="w-50 fw-bold text-center align-middle">{{ str(__('validation.custom.contract'))->ucFirst() }}</td>
<td class="w-50 text-center align-middle">
{{ $offerModel->contract }}
</td>
</tr>
<tr class="border-bottom">
<td class="w-50 fw-bold text-center align-middle">{{ str(__('validation.custom.function'))->ucFirst() }}</td>
<td class="w-50 text-center align-middle">
{{ $offerModel->function }}
</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">
{{ $offerModel->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($offerModel->picture) }}"
title="{{ $offerModel->picture_title }}" alt="{{ $offerModel->picture_alt }}">
</td>
</tr>
<tr class="border-bottom">
<td class="w-50 fw-bold text-center align-middle">
{{ str(sprintf("%s du bouton", __('validation.custom.publication')))->ucFirst() }}
</td>
<td class="w-50 text-center align-middle">
{{ $offerModel->published ? __('Oui') : __('Non') }}
</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($offerModel->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($offerModel->updated_at->isoFormat('LLLL'))->ucFirst() }}
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
@endsection

View file

@ -12,6 +12,7 @@ use App\Models\ConsumptionMoment;
use App\Models\MainSlide;
use App\Models\GeneralSetting;
use App\Models\Meat;
use App\Models\Offer;
use App\Models\Product;
use App\Models\ProductType;
use App\Models\Range;
@ -494,3 +495,27 @@ Breadcrumbs::for('bo.recipes.duplicate', function (Generator $trail) {
Breadcrumbs::for('bo.seo.index', function (Generator $trail) {
$trail->push(Str::of(trans('champs SEO'))->ucfirst(), route('bo.recipes.index'));
});
// * OFFERS
Breadcrumbs::for('bo.offers.index', function (Generator $trail) {
$trail->push(
Str::of(trans('models.classes.offer'))->ucfirst()->plural(),
route('bo.offers.index', ['sort_col' => 'updated_at', 'sort_way' => 'desc'])
);
});
Breadcrumbs::for('bo.offers.show', function (Generator $trail, Offer $offer) {
$trail->parent('bo.offers.index');
$trail->push(Str::ucfirst(trans('crud.actions.view')), route('bo.offers.show', $offer));
});
Breadcrumbs::for('bo.offers.create', function (Generator $trail) {
$trail->parent('bo.offers.index');
$trail->push(Str::ucfirst(trans('crud.actions.create')), route('bo.offers.create'));
});
Breadcrumbs::for('bo.offers.edit', function (Generator $trail, Offer $offer) {
$trail->parent('bo.offers.index');
$trail->push(Str::ucfirst(trans('crud.actions.edit')), route('bo.offers.edit', $offer));
});
Breadcrumbs::for('bo.offers.duplicate', function (Generator $trail) {
$trail->parent('bo.offers.index');
$trail->push(Str::ucfirst(trans('crud.actions.duplicate')));
});

View file

@ -12,6 +12,7 @@ use App\Http\Controllers\Bo\KeyNumberController;
use App\Http\Controllers\Bo\MainSlideController;
use App\Http\Controllers\Bo\MenuNodeDataController;
use App\Http\Controllers\Bo\MeatController;
use App\Http\Controllers\Bo\OfferController;
use App\Http\Controllers\Bo\ProductController;
use App\Http\Controllers\Bo\ProductTypeController;
use App\Http\Controllers\Bo\ProfessionController;
@ -320,6 +321,20 @@ Route::middleware(['throttle:web'])->prefix('bo')->name('bo.')->group(function (
Route::get('/products/json/paginate', [ProductController::class, 'jsonPaginateModels'])
->name('products.json-paginate');
// * OFFERS.
Route::resource('offers', OfferController::class)
->withoutMiddleware('htmlsanitize')
->middleware('htmlsanitize:description');
Route::patch('/offers/{offer}/change-published', [
OfferController::class, 'changePublished'
])->name('offers.change-published');
Route::patch('/offers/{offer}/change-order/{direction}', [
OfferController::class, 'changeOrder'
])->where('direction', 'up|down')->name('offers.change-order');
Route::get('/offers/{offer}/duplicate', [
OfferController::class, 'duplicate'
])->name('offers.duplicate');
Route::middleware('can:isConceptor')->group(function () {
// * ACTIVITY LOGS.
Route::resource('activity_logs', ActivityLogController::class)->only(['index', 'show']);