Added slides CRUD
This commit is contained in:
parent
bcb1fd1566
commit
4be4dddda0
16 changed files with 946 additions and 5 deletions
164
app/Http/Controllers/Bo/SlideController.php
Normal file
164
app/Http/Controllers/Bo/SlideController.php
Normal file
|
|
@ -0,0 +1,164 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Bo;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Bo\Slides\StoreSlideRequest;
|
||||
use App\Http\Requests\Bo\Slides\UpdateSlideRequest;
|
||||
use App\Models\Slide;
|
||||
use App\Traits\Controllers\ChangesModelOrder;
|
||||
use App\Traits\Controllers\UpdateModelPublished;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class SlideController extends Controller
|
||||
{
|
||||
use UpdateModelPublished;
|
||||
use ChangesModelOrder;
|
||||
|
||||
/**
|
||||
* Create the controller instance.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->authorizeResource(Slide::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 $slideModels */
|
||||
$slideModels = Slide::query();
|
||||
|
||||
/** @var string $search Search field */
|
||||
$search = $request->search;
|
||||
if ($search) {
|
||||
$this->searchQuery(
|
||||
$slideModels,
|
||||
$search,
|
||||
null,
|
||||
'slider',
|
||||
'title',
|
||||
);
|
||||
}
|
||||
$searchFields = \implode(', ', [
|
||||
Str::ucfirst(trans('validation.custom.slider')),
|
||||
trans('validation.attributes.title'),
|
||||
]);
|
||||
|
||||
/** Sort columns with a query */
|
||||
$this->sortQuery($slideModels);
|
||||
|
||||
/** Custom pagination */
|
||||
$slideModels = $this->paginate($slideModels);
|
||||
|
||||
return view('bo.pages.slides.index', compact('slideModels', 'search', 'searchFields'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @param \App\Models\Slide $slide
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function create(Slide $slide): \Illuminate\Contracts\View\View
|
||||
{
|
||||
return view('bo.pages.slides.create', ['slideModel' => $slide]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \App\Http\Requests\Bo\Slides\StoreSlideRequest $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function store(StoreSlideRequest $request): \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
return DB::transaction(function () use ($request) {
|
||||
$slide = new Slide();
|
||||
|
||||
if ($slide->fill($request->validated())->saveOrFail()) {
|
||||
return redirect()->route('bo.slides.edit', $slide)
|
||||
->with('success', __('crud.messages.has_been_created', [
|
||||
'model' => Str::ucfirst(__('models.classes.slide'))
|
||||
]));
|
||||
}
|
||||
return redirect()->back()
|
||||
->with('error', __('crud.messages.cannot_be_created', [
|
||||
'model' => Str::ucfirst(__('models.classes.slide'))
|
||||
]));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param App\Models\Slide $slide
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function edit(Slide $slide): \Illuminate\Contracts\View\View
|
||||
{
|
||||
return view('bo.pages.slides.edit', ['slideModel' => $slide]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \App\Http\Requests\Bo\Slides\UpdateSlideRequest $request
|
||||
* @param \App\Models\Slide $slide
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update(UpdateSlideRequest $request, Slide $slide): \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
return DB::transaction(function () use ($request, $slide) {
|
||||
if ($slide->fill($request->validated())->saveOrFail()) {
|
||||
return redirect()->route('bo.slides.edit', $slide)
|
||||
->with('success', __('crud.messages.has_been_updated', [
|
||||
'model' => Str::ucfirst(__('models.classes.slide'))
|
||||
]));
|
||||
}
|
||||
return redirect()->route('bo.slides.edit', $slide)
|
||||
->with('error', __('crud.messages.cannot_be_updated', [
|
||||
'model' => Str::ucfirst(__('models.classes.slide'))
|
||||
]));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\Slide $slide
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy(Slide $slide): \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
if ($slide->deleteOrFail()) {
|
||||
return redirect()->route('bo.slides.index')
|
||||
->with('success', __('crud.messages.has_been_deleted', [
|
||||
'model' => Str::ucfirst(__('models.classes.slide'))
|
||||
]));
|
||||
}
|
||||
return redirect()->back()
|
||||
->with('error', __('crud.messages.cannot_be_deleted', [
|
||||
'model' => Str::ucfirst(__('models.classes.slide'))
|
||||
]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Duplicate the specified resource.
|
||||
*
|
||||
* @param \App\Models\Slide $slide
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function duplicate(Slide $slide): \Illuminate\Contracts\View\View
|
||||
{
|
||||
return $this->create($slide->replicate());
|
||||
}
|
||||
}
|
||||
102
app/Http/Requests/Bo/Slides/StoreSlideRequest.php
Normal file
102
app/Http/Requests/Bo/Slides/StoreSlideRequest.php
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Bo\Slides;
|
||||
|
||||
use App\Traits\Requests\HasPicture;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rules\Enum;
|
||||
|
||||
class StoreSlideRequest extends FormRequest
|
||||
{
|
||||
use HasPicture;
|
||||
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return auth('backend')->check();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the data for validation.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function prepareForValidation()
|
||||
{
|
||||
$this->merge([
|
||||
'button_status' => $this->button_status ? true : false,
|
||||
'button_new_tab' => $this->button_new_tab ? true : false
|
||||
]);
|
||||
if (intval($this->slider) !== \App\Enums\Slides\SliderTypeEnum::home->value()) {
|
||||
$this->merge([
|
||||
'video_id' => ''
|
||||
]);
|
||||
};
|
||||
$this->mergePicture('picture');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
$rules = [
|
||||
'slider' => [
|
||||
'required',
|
||||
new Enum(\App\Enums\Slides\SliderTypeEnum::class)
|
||||
],
|
||||
'title' => [
|
||||
'required_unless:slider,' . \App\Enums\Slides\SliderTypeEnum::home->value(),
|
||||
'nullable',
|
||||
'string',
|
||||
'between:3,255'
|
||||
],
|
||||
'content' => 'required|string|between:3,255',
|
||||
'video_id' => 'nullable|string|regex:%([^"&?\/\s]{11})%i',
|
||||
'picture_alt' => 'required|string|between:3,255',
|
||||
'picture_title' => 'required|string|between:3,255',
|
||||
'button_label' => 'required_if:button_status,true|nullable|string|between:3,35',
|
||||
'button_url' => 'required_if:button_status,true|nullable|string|between:3,255',
|
||||
'button_status' => 'required|boolean',
|
||||
'button_new_tab' => 'required|boolean',
|
||||
];
|
||||
return \array_merge(
|
||||
$rules,
|
||||
// FIXME: Mettre à jour les tailles.
|
||||
$this->pictureRules('picture', 100, 100, 100, 100, null, false),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get custom attributes for validator errors.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function attributes(): array
|
||||
{
|
||||
return [
|
||||
|
||||
'video_id' => trans('validation.custom.video_id'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom validaton messages.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function messages()
|
||||
{
|
||||
return [
|
||||
'title' => [
|
||||
'required_unless' => __('Le champ titre est obligatoire si le slider n\'est pas home.'),
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
7
app/Http/Requests/Bo/Slides/UpdateSlideRequest.php
Normal file
7
app/Http/Requests/Bo/Slides/UpdateSlideRequest.php
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Bo\Slides;
|
||||
|
||||
class UpdateSlideRequest extends StoreSlideRequest
|
||||
{
|
||||
}
|
||||
|
|
@ -32,8 +32,10 @@ class Slide extends Model
|
|||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'slider',
|
||||
'title',
|
||||
'text',
|
||||
'content',
|
||||
'video_id',
|
||||
'button_status',
|
||||
'button_label',
|
||||
'button_url',
|
||||
|
|
|
|||
120
app/Policies/SlidePolicy.php
Normal file
120
app/Policies/SlidePolicy.php
Normal file
|
|
@ -0,0 +1,120 @@
|
|||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Enums\Users\RoleEnum;
|
||||
use App\Models\User;
|
||||
use App\Policies\Rules\UserStaticRules;
|
||||
|
||||
class SlidePolicy
|
||||
{
|
||||
/**
|
||||
* Determine whether the user can view any models.
|
||||
*
|
||||
* @param \App\Models\User $authUser
|
||||
* @return boolean
|
||||
*/
|
||||
public function viewAny(User $authUser): bool
|
||||
{
|
||||
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 models.
|
||||
*
|
||||
* @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 restore the model.
|
||||
*
|
||||
* @param \App\Models\User $authUser
|
||||
* @return boolean
|
||||
*/
|
||||
public function restore(User $authUser): bool
|
||||
{
|
||||
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can permanently delete the model.
|
||||
*
|
||||
* @param \App\Models\User $authUser
|
||||
* @return boolean
|
||||
*/
|
||||
public function forceDelete(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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can change the order of the model.
|
||||
*
|
||||
* @param \App\Models\User $authUser
|
||||
* @return boolean
|
||||
*/
|
||||
public function changeOrder(User $authUser): bool
|
||||
{
|
||||
return UserStaticRules::atLeastRole($authUser, RoleEnum::admin);
|
||||
}
|
||||
}
|
||||
|
|
@ -10,5 +10,6 @@ return [
|
|||
'site' => 'site',
|
||||
'logo' => 'logo',
|
||||
'historicalMilestone' => 'jalon historique|jalons historiques',
|
||||
'slide' => 'slide',
|
||||
]
|
||||
];
|
||||
|
|
|
|||
|
|
@ -266,6 +266,9 @@ return [
|
|||
'button_status' => 'status du bouton',
|
||||
'button_url' => 'lien du bouton',
|
||||
'button' => 'bouton',
|
||||
'url' => 'url',
|
||||
'url' => 'url',
|
||||
'video_id' => 'ID de la vidéo',
|
||||
'youtube_video' => 'vidéo YouTube',
|
||||
'slider' => 'slider',
|
||||
],
|
||||
];
|
||||
|
|
|
|||
|
|
@ -77,6 +77,14 @@
|
|||
</a>
|
||||
</li>
|
||||
@endcan
|
||||
@can('viewAny', \App\Models\Slide::class)
|
||||
<li class="nav-item">
|
||||
<a class="nav-link @if (request()->routeIs('bo.slides.*')) active @endif" data-bs-toggle="tooltip" href="{{ route('bo.slides.index') }}"
|
||||
title="{{ __('crud.helpers.list_all', ['model' => Str::of(__('models.classes.slide'))->title()]) }}">
|
||||
{{ Str::of(__('models.classes.slide'))->ucfirst()->plural() }}
|
||||
</a>
|
||||
</li>
|
||||
@endcan
|
||||
@can('viewAny', \App\Models\HistoricalMilestone::class)
|
||||
<li class="nav-item">
|
||||
<a class="nav-link @if (request()->routeIs('bo.historicalmilestones.*')) active @endif" data-bs-toggle="tooltip"
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
@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" data-bs-toggle="tooltip" href="{{ route('bo.site.index') }}"
|
||||
<a class="btn btn-primary text-decoration-none m-0" data-bs-toggle="tooltip" href="{{ route('bo.sites.index') }}"
|
||||
title="{{ __('crud.helpers.list_all', ['model' => __('models.classes.site')]) }}">
|
||||
<i class="fa-solid fa-arrow-left"></i>
|
||||
</a>
|
||||
|
|
@ -21,7 +21,7 @@
|
|||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<form action="{{ route('bo.site.store') }}" method="POST" enctype="multipart/form-data">
|
||||
<form action="{{ route('bo.sites.store') }}" method="POST" enctype="multipart/form-data">
|
||||
@csrf
|
||||
@include('bo.pages.sites.form')
|
||||
<div class="row mt-3">
|
||||
|
|
|
|||
36
resources/views/bo/pages/slides/create.blade.php
Normal file
36
resources/views/bo/pages/slides/create.blade.php
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
@extends('bo.layout', ['brParam' => $slideModel])
|
||||
|
||||
@section('title', __('Création d\'un :model', ['model' => __('models.classes.slide')]))
|
||||
@section('description', __('Création d\'un tout nouveau :model', ['model' => __('models.classes.slide')]))
|
||||
@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" data-bs-toggle="tooltip" href="{{ route('bo.slides.index') }}"
|
||||
title="{{ __('crud.helpers.list_all', ['model' => __('models.classes.slide')]) }}">
|
||||
<i class="fa-solid fa-arrow-left"></i>
|
||||
</a>
|
||||
@include('modules.breadcrumbs.breadcrumb-body', ['brParam' => $slideModel])
|
||||
</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.slide')]) }}">
|
||||
{{ Str::ucfirst(__('crud.actions.save')) }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<form action="{{ route('bo.slides.store') }}" method="POST" enctype="multipart/form-data">
|
||||
@csrf
|
||||
@include('bo.pages.slides.form')
|
||||
<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.slide')]) }}">
|
||||
{{ Str::ucfirst(__('crud.actions.save')) }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
@endsection
|
||||
52
resources/views/bo/pages/slides/edit.blade.php
Normal file
52
resources/views/bo/pages/slides/edit.blade.php
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
@extends('bo.layout', ['brParam' => $slideModel])
|
||||
|
||||
@section('title', __('Édition d\'une :model', ['model' => __('models.classes.slide')]))
|
||||
@section('description', __('Édition d\'une :model déjà existante', ['model' => __('models.classes.slide')]))
|
||||
@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" data-bs-toggle="tooltip" href="{{ route('bo.slides.index') }}"
|
||||
title="{{ __('crud.helpers.list_all', ['model' => Str::plural(__('models.classes.slide'))]) }}">
|
||||
<i class="fa-solid fa-arrow-left"></i>
|
||||
</a>
|
||||
@include('modules.breadcrumbs.breadcrumb-body', ['brParam' => $slideModel])
|
||||
</div>
|
||||
<div class="mb-md-0 mb-2">
|
||||
<form class="btn-group confirmDeleteTS" action="{{ route('bo.slides.destroy', $slideModel) }}" method="POST" novalidate>
|
||||
@can('duplicate', $slideModel)
|
||||
<a class="btn btn-secondary" data-bs-toggle="tooltip" href="{{ route('bo.slides.duplicate', ['slide' => $slideModel]) }}"
|
||||
title="{{ Str::ucfirst(__('crud.actions.duplicate')) }}">
|
||||
<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.slide')]) }}">
|
||||
{{ Str::ucfirst(__('crud.actions.save')) }}
|
||||
</button>
|
||||
@can('delete', $slideModel)
|
||||
@csrf
|
||||
@method('DELETE')
|
||||
<button class="btn btn-danger" data-bs-toggle="tooltip" type="submit" title="{{ Str::ucfirst(__('crud.actions.delete')) }}">
|
||||
<i class="fa-solid fa-trash"></i>
|
||||
</button>
|
||||
@endcan
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<form action="{{ route('bo.slides.update', $slideModel) }}" method="POST" enctype="multipart/form-data">
|
||||
@csrf
|
||||
@method('PUT')
|
||||
@include('bo.pages.slides.form')
|
||||
<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.slide')]) }}">
|
||||
{{ Str::ucfirst(__('crud.actions.save')) }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
@endsection
|
||||
324
resources/views/bo/pages/slides/form.blade.php
Normal file
324
resources/views/bo/pages/slides/form.blade.php
Normal file
|
|
@ -0,0 +1,324 @@
|
|||
<div class="row">
|
||||
{{-- SLIDER --}}
|
||||
<div class="col-12 col-md-6 mb-3">
|
||||
<fieldset class="h-100 border p-3">
|
||||
<legend>{{ Str::ucfirst(__('validation.custom.slider')) }}</legend>
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
@include('bo.partials.inputs.tinyint-enum', [
|
||||
'id' => 'slideSlider',
|
||||
'label' => __('Associer un slider'),
|
||||
'name' => 'slider',
|
||||
'model' => $slideModel ?? null,
|
||||
'required' => true,
|
||||
'associatedModels' => \App\Enums\Slides\SliderTypeEnum::toArray(),
|
||||
'helper' => __('Sélectionnez un slider dans la liste déroulante.'),
|
||||
])
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
{{-- TITLE --}}
|
||||
<div class="col-12 col-md-6 mb-3">
|
||||
<fieldset class="h-100 border p-3">
|
||||
<legend>{{ Str::ucfirst(__('validation.attributes.title')) }}</legend>
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
@include('bo.partials.inputs.varchar', [
|
||||
'id' => 'slideTitle',
|
||||
'label' => __(':field :inter:model', [
|
||||
'field' => Str::ucfirst(__('validation.attributes.title')),
|
||||
'inter' => __('validation.custom.of_the.female'),
|
||||
'model' => __('models.classes.slide'),
|
||||
]),
|
||||
'hasWordCounter' => true,
|
||||
'name' => 'title',
|
||||
'required' => false,
|
||||
'model' => $slideModel ?? null,
|
||||
'helper' => __('validation.between.string', [
|
||||
'attribute' => __(':field :inter:model', [
|
||||
'field' => __('validation.attributes.title'),
|
||||
'inter' => __('validation.custom.of_the.female'),
|
||||
'model' => __('models.classes.slide'),
|
||||
]),
|
||||
'min' => 3,
|
||||
'max' => 100,
|
||||
]),
|
||||
'placeholder' => __('Un titre clair et concis'),
|
||||
])
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
{{-- CONTENT --}}
|
||||
<div class="col-12 col-md-6 mb-3">
|
||||
<fieldset class="h-100 border p-3">
|
||||
<legend>{{ Str::ucfirst(__('validation.attributes.content')) }}</legend>
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
@include('bo.partials.inputs.varchar-multiline', [
|
||||
'id' => 'slideContent',
|
||||
'label' => __(':field :inter:model', [
|
||||
'field' => Str::ucfirst(__('validation.attributes.content')),
|
||||
'inter' => __('validation.custom.of_the.female'),
|
||||
'model' => __('models.classes.slide'),
|
||||
]),
|
||||
'hasWordCounter' => true,
|
||||
'name' => 'content',
|
||||
'required' => false,
|
||||
'model' => $slideModel ?? null,
|
||||
'helper' => __('validation.between.string', [
|
||||
'attribute' => __(':field :inter:model', [
|
||||
'field' => __('validation.attributes.content'),
|
||||
'inter' => __('validation.custom.of_the.female'),
|
||||
'model' => __('models.classes.slide'),
|
||||
]),
|
||||
'min' => 3,
|
||||
'max' => 255,
|
||||
]),
|
||||
'placeholder' => __('Contenu textuel de la slide'),
|
||||
])
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
{{-- VIDEO ID --}}
|
||||
<div class="col-12 col-md-6 mb-3" id="video_id_input" hidden>
|
||||
<fieldset class="h-100 border p-3">
|
||||
<legend>{{ Str::ucfirst(__('validation.custom.youtube_video')) }}</legend>
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
@include('bo.partials.inputs.varchar', [
|
||||
'id' => 'slideVideo',
|
||||
'label' => __(':field :inter:model', [
|
||||
'field' => Str::ucfirst(__('validation.custom.video_id')),
|
||||
'inter' => __('validation.custom.of_the.female'),
|
||||
'model' => __('models.classes.slide'),
|
||||
]),
|
||||
'hasWordCounter' => true,
|
||||
'name' => 'video_id',
|
||||
'required' => false,
|
||||
'model' => $slideModel ?? null,
|
||||
'helper' =>
|
||||
__('validation.between.string', [
|
||||
'attribute' => __(':field :inter:model', [
|
||||
'field' => __('validation.custom.video_id'),
|
||||
'inter' => __('validation.custom.of_the.female'),
|
||||
'model' => __('models.classes.slide'),
|
||||
]),
|
||||
'min' => 3,
|
||||
'max' => 255,
|
||||
]) . __(' Doit être l\'id de la vidéo.'),
|
||||
'placeholder' => __('crud.placeholders.beautiful', ['field' => __('validation.attributes.url')]),
|
||||
])
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
|
||||
{{-- PICTURE --}}
|
||||
<div class="col-12 pb-3">
|
||||
<fieldset class="h-100 border p-3">
|
||||
<legend>{{ Str::ucfirst(__('validation.attributes.image')) }}</legend>
|
||||
<div class="row mb-3">
|
||||
{{-- PICTURE_ALT --}}
|
||||
<div class="col-12 col-md-6 m-md-0 mb-3">
|
||||
@include('bo.partials.inputs.varchar', [
|
||||
'id' => 'slidePictureAlt',
|
||||
'label' => __(':field1 :inter1:field2 :inter2:model', [
|
||||
'field1' => Str::ucfirst(__('validation.custom.alt_attribute')),
|
||||
'inter1' => __('validation.custom.of_the.male'),
|
||||
'field2' => __('validation.attributes.image'),
|
||||
'inter2' => __('validation.custom.of_the.male'),
|
||||
'model' => __('models.classes.slide'),
|
||||
]),
|
||||
'hasWordCounter' => true,
|
||||
'name' => 'picture_alt',
|
||||
'required' => true,
|
||||
'model' => $slideModel ?? null,
|
||||
'helper' => __('crud.minicrud.picture_alt_helper'),
|
||||
'placeholder' => __(':field1 :inter1:field2 :inter2:model', [
|
||||
'field1' => Str::ucfirst(__('validation.custom.alt_attribute')),
|
||||
'inter1' => __('validation.custom.of_the.male'),
|
||||
'field2' => __('validation.attributes.image'),
|
||||
'inter2' => __('validation.custom.of_the.male'),
|
||||
'model' => __('models.classes.slide'),
|
||||
]),
|
||||
])
|
||||
</div>
|
||||
{{-- PICTURE_TITLE --}}
|
||||
<div class="col-12 col-md-6 mb-3">
|
||||
@include('bo.partials.inputs.varchar', [
|
||||
'id' => 'slidePictureTitle',
|
||||
'label' => __(':field1 :inter1:field2 :inter2:model', [
|
||||
'field1' => Str::ucfirst(__('validation.custom.title_attribute')),
|
||||
'inter1' => __('validation.custom.of_the.male'),
|
||||
'field2' => __('validation.attributes.image'),
|
||||
'inter2' => __('validation.custom.of_the.male'),
|
||||
'model' => __('models.classes.slide'),
|
||||
]),
|
||||
'hasWordCounter' => true,
|
||||
'name' => 'picture_title',
|
||||
'required' => true,
|
||||
'model' => $slideModel ?? null,
|
||||
'helper' => __('crud.minicrud.picture_title_helper'),
|
||||
'placeholder' => __(':field1 :inter1:field2 :inter2:model', [
|
||||
'field1' => Str::ucfirst(__('validation.custom.title_attribute')),
|
||||
'inter1' => __('validation.custom.of_the.male'),
|
||||
'field2' => __('validation.attributes.image'),
|
||||
'inter2' => __('validation.custom.of_the.male'),
|
||||
'model' => __('models.classes.slide'),
|
||||
]),
|
||||
])
|
||||
</div>
|
||||
{{-- PICTURE --}}
|
||||
<div class="col-12">
|
||||
@include('bo.partials.inputs.varchar-picture', [
|
||||
'id' => 'slidePicture',
|
||||
'name' => 'picture',
|
||||
'width' => 100,
|
||||
'height' => 100,
|
||||
'model' => $slideModel ?? null,
|
||||
'helper' => __('crud.minicrud.dimensions_must_be', [
|
||||
'widthpx' => '100px',
|
||||
'heightpx' => '100px',
|
||||
]),
|
||||
'required' => true,
|
||||
'preview' => true,
|
||||
])
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
{{-- BUTTON --}}
|
||||
<div class="col-12 pb-3">
|
||||
<fieldset class="h-100 border p-3">
|
||||
<legend>{{ Str::ucfirst(__('validation.custom.button')) }}</legend>
|
||||
<div class="row mb-3">
|
||||
{{-- BUTTON_LABEL --}}
|
||||
<div class="col-12 col-md-6 mb-3">
|
||||
@include('bo.partials.inputs.varchar', [
|
||||
'id' => 'slideButtonLabel',
|
||||
'label' => __(':field :inter:model', [
|
||||
'field' => Str::ucfirst(__('validation.custom.label')),
|
||||
'inter' => __('validation.custom.of_the.male'),
|
||||
'model' => __('validation.custom.button'),
|
||||
]),
|
||||
'hasWordCounter' => true,
|
||||
'name' => 'button_label',
|
||||
'required' => false,
|
||||
'model' => $slideModel ?? null,
|
||||
'helper' => __('validation.between.string', [
|
||||
'attribute' => __(':field :inter:model', [
|
||||
'field' => __('validation.custom.label'),
|
||||
'inter' => __('validation.custom.of_the.male'),
|
||||
'model' => __('validation.custom.button'),
|
||||
]),
|
||||
'min' => 3,
|
||||
'max' => 35,
|
||||
]),
|
||||
'placeholder' => __(':field :inter:model', [
|
||||
'field' => Str::ucfirst(__('validation.custom.label')),
|
||||
'inter' => __('validation.custom.of_the.male'),
|
||||
'model' => __('validation.custom.button'),
|
||||
]),
|
||||
])
|
||||
</div>
|
||||
{{-- BUTTON_URL --}}
|
||||
<div class="col-12 col-md-6 mb-3">
|
||||
@include('bo.partials.inputs.varchar-url', [
|
||||
'id' => 'slideButtonUrl',
|
||||
'label' => __(':field :inter:model', [
|
||||
'field' => Str::ucfirst(__('validation.custom.url')),
|
||||
'inter' => __('validation.custom.of_the.male'),
|
||||
'model' => __('validation.custom.button'),
|
||||
]),
|
||||
'hasWordCounter' => true,
|
||||
'name' => 'button_url',
|
||||
'required' => false,
|
||||
'model' => $slideModel ?? null,
|
||||
'helper' => __('crud.helpers.url'),
|
||||
'placeholder' => __(':field :inter:model', [
|
||||
'field' => Str::ucfirst(__('validation.custom.url')),
|
||||
'inter' => __('validation.custom.of_the.male'),
|
||||
'model' => __('validation.custom.button'),
|
||||
]),
|
||||
])
|
||||
</div>
|
||||
{{-- BUTTON_NEW_TAB --}}
|
||||
<div class="col-12 col-md-6 mb-3">
|
||||
<label class="col-form-label mb-3 p-0" for="slideButtonNewTab" type="button">
|
||||
<b>{{ Str::ucfirst(__('validation.custom.target')) }}</b>
|
||||
</label>
|
||||
@include('bo.partials.inputs.tinyint-boolean', [
|
||||
'id' => 'slideButtonNewTab',
|
||||
'name' => 'button_new_tab',
|
||||
'model' => $slideModel ?? null,
|
||||
'label' => __('crud.labels.new_tab_boolean'),
|
||||
'helper' => __('crud.helpers.new_tab_boolean'),
|
||||
])
|
||||
</div>
|
||||
{{-- BUTTON_STATUS --}}
|
||||
<div class="col-12 col-md-6 mb-3">
|
||||
<label class="col-form-label mb-3 p-0" for="slideButtonStatus" type="button">
|
||||
<b>{{ __('crud.minicrud.visibility_label') }}</b>
|
||||
</label>
|
||||
@include('bo.partials.inputs.tinyint-boolean', [
|
||||
'id' => 'slideButtonStatus',
|
||||
'name' => 'button_status',
|
||||
'model' => $slideModel ?? null,
|
||||
'label' => __(':field1 :inter:field2', [
|
||||
'field1' => __('crud.minicrud.visibility_label'),
|
||||
'inter' => __('validation.custom.of_the.male'),
|
||||
'field2' => __('validation.custom.button'),
|
||||
]),
|
||||
'helper' => __('crud.minicrud.visibility_helper'),
|
||||
])
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col text-center">
|
||||
<p><b>* {{ __('crud.helpers.required_fields') }}</b></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@push('scripts')
|
||||
<script nonce="{{ $nonce }}">
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
// Submit button clone.
|
||||
const submit = document.getElementById('formSubmit')
|
||||
submitClone = document.getElementById('formSubmitClone');
|
||||
submitClone.addEventListener('click', (event) => {
|
||||
event.preventDefault();
|
||||
submit.click('');
|
||||
})
|
||||
|
||||
// Update inputs for sliders other than 'home'.
|
||||
const sliderInput = document.getElementById('slider');
|
||||
const videoIdField = document.getElementById('video_id_input');
|
||||
const titleInput = document.getElementById('slideTitle');
|
||||
|
||||
if (sliderInput.value === "{{ \App\Enums\Slides\SliderTypeEnum::home->value() }}") {
|
||||
videoIdField.hidden = false;
|
||||
titleInput.required = false;
|
||||
} else {
|
||||
videoIdField.hidden = true;
|
||||
titleInput.required = true;
|
||||
}
|
||||
|
||||
sliderInput.addEventListener('input', () => {
|
||||
if (sliderInput.value === "{{ \App\Enums\Slides\SliderTypeEnum::home->value() }}") {
|
||||
videoIdField.hidden = false;
|
||||
titleInput.required = false;
|
||||
} else {
|
||||
videoIdField.hidden = true;
|
||||
titleInput.required = true;
|
||||
}
|
||||
})
|
||||
});
|
||||
</script>
|
||||
@endpush
|
||||
74
resources/views/bo/pages/slides/index-list.blade.php
Normal file
74
resources/views/bo/pages/slides/index-list.blade.php
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
<table class="table-hover table-fix-action m-0 table">
|
||||
@if (count($slideModels) > 0)
|
||||
<thead>
|
||||
@include('bo.modules.table-col-sorter', [
|
||||
'cols' => [
|
||||
'slider' => Str::ucfirst(__('validation.custom.slider')),
|
||||
'title' => Str::ucfirst(__('validation.attributes.title')),
|
||||
'order' => Str::ucfirst(__('validation.custom.order')),
|
||||
'updated_at' => Str::ucfirst(__('validation.attributes.updated_at')),
|
||||
],
|
||||
])
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach ($slideModels as $slideModel)
|
||||
<tr class="border-bottom list-item">
|
||||
<td class="text-center align-middle">{{ $slideModel->slider->label() }}</td>
|
||||
<td class="text-center align-middle">{{ $slideModel->title }}</td>
|
||||
@php
|
||||
$routeName = request()
|
||||
->route()
|
||||
->getName();
|
||||
@endphp
|
||||
@if (empty(request()->search) && Session::get("$routeName.sort_col") === 'order')
|
||||
@include('bo.modules.change-model-order', [
|
||||
'routeName' => 'slides',
|
||||
'model' => $slideModel,
|
||||
'models' => $slideModels,
|
||||
])
|
||||
@endif
|
||||
<td class="text-center align-middle">
|
||||
<span class="badge bg-secondary">{{ $slideModel->updated_at->isoFormat('LLLL') }}</span>
|
||||
</td>
|
||||
<td class="text-end align-middle">
|
||||
@canAny(['delete', 'duplicate', 'update'], $slideModel)
|
||||
<form class="btn-group confirmDeleteTS" action="{{ route('bo.slides.destroy', $slideModel) }}" method="POST"
|
||||
novalidate>
|
||||
@can('duplicate', $slideModel)
|
||||
<a class="btn btn-sm btn-secondary" data-bs-toggle="tooltip"
|
||||
href="{{ route('bo.slides.duplicate', ['slide' => $slideModel]) }}"
|
||||
title="{{ Str::ucfirst(__('crud.actions.duplicate')) }}">
|
||||
<i class="fa-solid fa-copy"></i>
|
||||
</a>
|
||||
@endcan
|
||||
@can('update', $slideModel)
|
||||
<a class="btn btn-sm btn-primary" data-bs-toggle="tooltip"
|
||||
href="{{ route('bo.slides.edit', ['slide' => $slideModel]) }}"
|
||||
title="{{ Str::ucfirst(__('crud.actions.update')) }}">
|
||||
<i class="fa-solid fa-pencil"></i>
|
||||
</a>
|
||||
@endcan
|
||||
@can('delete', $slideModel)
|
||||
@csrf
|
||||
@method('DELETE')
|
||||
<button class="btn btn-sm btn-danger" data-bs-toggle="tooltip" type="submit"
|
||||
title="{{ Str::ucfirst(__('crud.actions.delete')) }}">
|
||||
<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">{{ __('crud.other.no_model_found', ['model' => __('models.classes.slide')]) }}</td>
|
||||
</tr>
|
||||
@endif
|
||||
</table>
|
||||
21
resources/views/bo/pages/slides/index.blade.php
Normal file
21
resources/views/bo/pages/slides/index.blade.php
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
@extends('bo.layout')
|
||||
|
||||
@section('title', Str::ucfirst(__('models.classes.slide')))
|
||||
@section('description', __('Liste de tous les :model', ['model' => Str::plural(__('models.classes.slide'))]))
|
||||
|
||||
@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\Slide::class)
|
||||
<a class="btn btn-primary float-right" data-bs-toggle="tooltip" href="{{ route('bo.slides.create') }}"
|
||||
title="{{ __('crud.helpers.create_model', ['model' => __('models.classes.slide')]) }}">
|
||||
<i class="fa-solid fa-plus"></i>
|
||||
</a>
|
||||
@endcan
|
||||
</div>
|
||||
@include('bo.modules.search-bar')
|
||||
<div class="table-responsive mb-3">
|
||||
@include('bo.pages.slides.index-list')
|
||||
</div>
|
||||
{{ $slideModels->links() }}
|
||||
@endsection
|
||||
|
|
@ -6,6 +6,7 @@ use App\Models\Logo;
|
|||
use App\Models\News;
|
||||
use App\Models\Section;
|
||||
use App\Models\Site;
|
||||
use App\Models\Slide;
|
||||
use App\Models\StaticPage;
|
||||
use App\Models\User;
|
||||
use Diglactic\Breadcrumbs\Breadcrumbs;
|
||||
|
|
@ -136,6 +137,26 @@ Breadcrumbs::for('bo.historicalmilestones.duplicate', function (Generator $trail
|
|||
$trail->push(Str::ucfirst(trans('crud.actions.duplicate')));
|
||||
});
|
||||
|
||||
// * SLIDES
|
||||
Breadcrumbs::for('bo.slides.index', function (Generator $trail) {
|
||||
$trail->push(
|
||||
Str::of(trans('models.classes.slide'))->plural()->ucfirst(),
|
||||
route('bo.slides.index', ['sort_col' => 'updated_at', 'sort_way' => 'desc'])
|
||||
);
|
||||
});
|
||||
Breadcrumbs::for('bo.slides.create', function (Generator $trail) {
|
||||
$trail->parent('bo.slides.index');
|
||||
$trail->push(Str::ucfirst(trans('crud.actions.create')), route('bo.slides.create'));
|
||||
});
|
||||
Breadcrumbs::for('bo.slides.edit', function (Generator $trail, Slide $slide) {
|
||||
$trail->parent('bo.slides.index');
|
||||
$trail->push(Str::ucfirst(trans('crud.actions.edit')), route('bo.slides.edit', $slide));
|
||||
});
|
||||
Breadcrumbs::for('bo.slides.duplicate', function (Generator $trail) {
|
||||
$trail->parent('bo.slides.index');
|
||||
$trail->push(Str::ucfirst(trans('crud.actions.duplicate')));
|
||||
});
|
||||
|
||||
// * SECTIONS
|
||||
Breadcrumbs::for('bo.sections.index', function (Generator $trail) {
|
||||
$trail->push(
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ use App\Http\Controllers\Bo\LogoController;
|
|||
use App\Http\Controllers\Bo\NewsController;
|
||||
use App\Http\Controllers\Bo\SectionController;
|
||||
use App\Http\Controllers\Bo\SiteController;
|
||||
use App\Http\Controllers\Bo\SlideController;
|
||||
use App\Http\Controllers\Bo\StaticPageController;
|
||||
use App\Http\Controllers\Bo\UploadController;
|
||||
use App\Http\Controllers\Bo\UserController;
|
||||
|
|
@ -69,7 +70,7 @@ Route::prefix('bo')
|
|||
// * SITES.
|
||||
Route::resource('sites', SiteController::class)->except('show')
|
||||
->withoutMiddleware('htmlsanitize')
|
||||
->middleware('htmlsanitize:director_speach,employee_speach,highlights');
|
||||
->middleware('htmlsanitize:director_speach,employee_speach,highlights,content');
|
||||
Route::patch('/sites/{site}/change-order/{direction}', [
|
||||
SiteController::class, 'changeOrder'
|
||||
])->where('direction', 'up|down')->name('sites.change-order');
|
||||
|
|
@ -90,6 +91,11 @@ Route::prefix('bo')
|
|||
HistoricalMilestoneController::class, 'duplicate'
|
||||
])->name('historicalmilestones.duplicate');
|
||||
|
||||
// * SLIDES.
|
||||
Route::resource('slides', SlideController::class)->except('show');
|
||||
Route::get('/slides/{slide}/duplicate', [
|
||||
SlideController::class, 'duplicate'
|
||||
])->name('slides.duplicate');
|
||||
|
||||
// * SECTIONS.
|
||||
Route::resource('sections', SectionController::class)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue