diff --git a/app/Http/Controllers/Bo/HomepageController.php b/app/Http/Controllers/Bo/HomepageController.php new file mode 100644 index 0000000..31964aa --- /dev/null +++ b/app/Http/Controllers/Bo/HomepageController.php @@ -0,0 +1,93 @@ +authorizeResource(Homepage::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 $homepageModels */ + $homepageModels = Homepage::query(); + + /** @var string $search Search field */ + $search = $request->search; + if ($search) { + $this->searchQuery( + $homepageModels, + $search, + null, + 'title_part1', + 'title_part2', + 'title_part3' + ); + } + $searchFields = \implode(', ', [ + Str::ucfirst(trans('validation.attributes.title')) + ]); + + /** Sort columns with a query */ + $this->sortQuery($homepageModels); + + /** Custom pagination */ + $homepageModels = $this->paginate($homepageModels); + + return view('bo.pages.homepages.index', compact('homepageModels', 'search', 'searchFields')); + } + + /** + * Show the form for editing the specified resource. + * + * @param App\Models\Homepage $homepage + * @return \Illuminate\Contracts\View\View + */ + public function edit(Homepage $homepage): \Illuminate\Contracts\View\View + { + return view('bo.pages.homepages.edit', ['homepageModel' => $homepage]); + } + + /** + * Update the specified resource in storage. + * + * @param \App\Http\Requests\Bo\Homepages\UpdateHomepageRequest $request + * @param \App\Models\Homepage $homepage + * @return \Illuminate\Http\RedirectResponse + */ + public function update(UpdateHomepageRequest $request, Homepage $homepage): \Illuminate\Http\RedirectResponse + { + return DB::transaction(function () use ($request, $homepage) { + $homepage->fill($request->validated()); + + if ($homepage->saveOrFail()) { + return redirect()->route('bo.homepages.edit', $homepage) + ->with('success', __('crud.messages.has_been_updated', [ + 'model' => Str::ucfirst(__('models.classes.homepage')) + ])); + } + return redirect()->route('bo.homepages.edit', $homepage) + ->with('error', __('crud.messages.cannot_be_updated', [ + 'model' => Str::ucfirst(__('models.classes.homepage')) + ])); + }); + } +} diff --git a/app/Http/Requests/Bo/Homepage/StoreHomepageRequest.php b/app/Http/Requests/Bo/Homepage/StoreHomepageRequest.php new file mode 100644 index 0000000..f6b0d87 --- /dev/null +++ b/app/Http/Requests/Bo/Homepage/StoreHomepageRequest.php @@ -0,0 +1,53 @@ +check(); + } + + /** + * Prepare the data for validation. + * + * @return void + */ + protected function prepareForValidation() + { + $this->mergePicture('picture'); + } + + /** + * Get the validation rules that apply to the request. + * + * @return array + */ + public function rules() + { + $rules = [ + 'title_part1' => 'required|string|between:3,255', + 'title_part2' => 'required|string|between:3,255', + 'title_part3' => 'required|string|between:3,255', + 'picture_alt' => 'required|string|between:3,255', + 'picture_title' => 'required|string|between:3,255', + 'presentation_title' => 'required|string|between:3,255', + 'presentation_content' => 'required|string', + ]; + return \array_merge( + $rules, + $this->pictureRules('picture', 640, 390, 640, 390, false), + ); + } +} diff --git a/app/Http/Requests/Bo/Homepage/UpdateHomepageRequest.php b/app/Http/Requests/Bo/Homepage/UpdateHomepageRequest.php new file mode 100644 index 0000000..a102925 --- /dev/null +++ b/app/Http/Requests/Bo/Homepage/UpdateHomepageRequest.php @@ -0,0 +1,18 @@ + */ protected $fillable = [ - 'title_part_1', - 'title_part_2', - 'title_part_3', + 'title_part1', + 'title_part2', + 'title_part3', 'picture', 'picture_alt', 'picture_title', diff --git a/app/Policies/HomepagePolicy.php b/app/Policies/HomepagePolicy.php new file mode 100644 index 0000000..27ab78c --- /dev/null +++ b/app/Policies/HomepagePolicy.php @@ -0,0 +1,43 @@ + 'Must give a precise description of the page, which is recommended for optimum positioning in search engines (
* {{ __('crud.helpers.required_fields') }}
+| {{ $homepageModel->title_part1 }} | +{{ $homepageModel->title_part2 }} | +{{ $homepageModel->title_part3 }} | +
+ |
+ {{ $homepageModel->presentation_title }} | +{!! Str::limit($homepageModel->presentation_content, 100) !!} | ++ {{ $homepageModel->updated_at->isoFormat('LLLL') }} + | + @php + $routeName = request() + ->route() + ->getName(); + @endphp ++ @canAny(['update'], $homepageModel) + + @else + + + + @endcan + | +
| {{ __('crud.other.no_model_found', ['model' => __('models.classes.homepage')]) }} | +