Compare commits
212 commits
admin-secu
...
develop
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
162b4a6451 | ||
| de5ef8d70e | |||
|
|
41a8a032af | ||
|
|
eef38c02d5 | ||
|
|
da89d39521 | ||
|
|
92cd02fd27 | ||
|
|
965e4867aa | ||
|
|
08f592e141 | ||
|
|
3b58f67701 | ||
|
|
7bcd3feb02 | ||
|
|
ef45646bf3 | ||
|
|
2e8d3ce15d | ||
|
|
5fb7c29d70 | ||
|
|
1fc0dddc30 | ||
|
|
6dd1c429d4 | ||
|
|
df97c19d5e | ||
|
|
503a8f1efd | ||
|
|
58af5b7922 | ||
|
|
86727e4d3c | ||
|
|
7a001ab811 | ||
|
|
f3db8cf28f | ||
|
|
bb5e56e172 | ||
|
|
303ac8cab4 | ||
|
|
23164bd6c8 | ||
|
|
ef72b9c99a | ||
|
|
98a84c1dd9 | ||
|
|
86e8662dbc | ||
|
|
4d193061fa | ||
|
|
0f8b79d77c | ||
|
|
40d1e7f04b | ||
|
|
b32f19fdb9 | ||
|
|
72e16d1715 | ||
|
|
6068573793 | ||
|
|
8193aaa597 | ||
|
|
801b876df5 | ||
|
|
0327175fc5 | ||
|
|
80ae4d966b | ||
|
|
312ca41b9c | ||
|
|
5195c59687 | ||
|
|
fe2379e302 | ||
|
|
a5312f3a5a | ||
|
|
18d8ce80b5 | ||
|
|
7599240975 | ||
|
|
2c0456c735 | ||
|
|
3092c16b2f | ||
|
|
3df66b6874 | ||
|
|
385a408d83 | ||
|
|
3b1d071943 | ||
|
|
623fb37d39 | ||
|
|
35f395bb58 | ||
|
|
d636dcfaf6 | ||
|
|
12d2545e9b | ||
|
|
e4a7c9533f | ||
|
|
2f87a92bfa | ||
|
|
240d6257a7 | ||
|
|
806262e8b7 | ||
|
|
bea39f3132 | ||
|
|
df019d230b | ||
|
|
91bab690d7 | ||
|
|
69bebfc92a | ||
|
|
75469508a6 | ||
|
|
390b38e43a | ||
|
|
95e0efe6ff | ||
|
|
7af694a6af | ||
|
|
9c22e8d16c | ||
|
|
2e59cc915b | ||
|
|
edb7206a1e | ||
|
|
31a19fc846 | ||
|
|
c54ffd1e01 | ||
|
|
0fcf0b9ba4 | ||
|
|
f76a855707 | ||
|
|
fc538f9668 | ||
|
|
a040e1f31d | ||
|
|
b4ecf09d1f | ||
|
|
21165b29e7 | ||
|
|
0b4e410e9d | ||
|
|
7bae433a1a | ||
|
|
212b41a451 | ||
|
|
23dc6307cd | ||
|
|
08b2d56f82 | ||
|
|
ac197b3827 | ||
|
|
a6ec394ade | ||
|
|
edcfc912c5 | ||
|
|
3335cf8634 | ||
|
|
d205e51337 | ||
|
|
388ab64000 | ||
|
|
6dd90e283d | ||
|
|
5365906e27 | ||
|
|
e1c971ef13 | ||
|
|
a77ace0615 | ||
|
|
0ba88f51eb | ||
|
|
c08266d81b | ||
|
|
af65a8d458 | ||
|
|
f5d1a8d215 | ||
|
|
d6f82c9df1 | ||
|
|
c081208cd3 | ||
|
|
01463b185e | ||
|
|
7b659d3120 | ||
|
|
222347d890 | ||
|
|
2104c27427 | ||
|
|
bdb2f9c149 | ||
|
|
4a145cd8f4 | ||
|
|
252e067cbb | ||
|
|
4f8975e4ed | ||
|
|
072ceae5b2 | ||
|
|
1a516842c3 | ||
|
|
c8947adc5b | ||
|
|
0beacf4846 | ||
|
|
25ad0e6f1d | ||
|
|
a0581cb398 | ||
|
|
b8956d5653 | ||
|
|
b882a81053 | ||
|
|
9916a0f348 | ||
|
|
a7469de5c6 | ||
|
|
9e846933d7 | ||
|
|
e155a26d2a | ||
|
|
b5de55f31f | ||
|
|
cfb74382a9 | ||
|
|
6c9e430566 | ||
|
|
c43c1559cd | ||
|
|
18d7357219 | ||
|
|
8454328693 | ||
|
|
59ea6fcb23 | ||
|
|
0559b21b89 | ||
|
|
66ccd487ce | ||
|
|
7fbddaca24 | ||
|
|
e5efdb32fc | ||
|
|
071a3e05c2 | ||
|
|
62571fcec6 | ||
|
|
831698f44b | ||
|
|
7cc2acc252 | ||
|
|
4299a7834f | ||
|
|
950e1f1b47 | ||
|
|
af56adc577 | ||
|
|
b76dd6e9f9 | ||
|
|
61efed1f74 | ||
|
|
295e4eb2e1 | ||
|
|
feaf9fd9d4 | ||
|
|
bdba7bb889 | ||
|
|
e4cdc7c652 | ||
|
|
b4578d1f75 | ||
|
|
601a5e967b | ||
|
|
436bdb40ab | ||
|
|
7aee1fd616 | ||
|
|
9ccbfb41f6 | ||
|
|
87142052e9 | ||
|
|
47bc061878 | ||
|
|
0ec9228a43 | ||
|
|
d4360b486f | ||
|
|
cbf82481ce | ||
|
|
086a5c8461 | ||
|
|
ac5164ab29 | ||
|
|
ea8541209a | ||
|
|
8988559c68 | ||
|
|
09803e015c | ||
|
|
1420bb52e6 | ||
|
|
1039d91f18 | ||
|
|
28f4baa8e3 | ||
|
|
ce62ad8020 | ||
|
|
53a77e8a0e | ||
|
|
7f1cf742a7 | ||
|
|
f5f2f511fe | ||
|
|
6043f7c8cc | ||
|
|
0b3e487636 | ||
|
|
6fbad46d90 | ||
|
|
5cfbb17f7b | ||
|
|
c9ca0b17bf | ||
|
|
8d83cd3b4d | ||
|
|
d58d0e5f2a | ||
|
|
0417c73d4a | ||
|
|
c1369ea508 | ||
|
|
9ce41966bc | ||
|
|
67e1273128 | ||
|
|
3857f1ab79 | ||
|
|
61c00d0bb0 | ||
|
|
998f7e0a8a | ||
|
|
568ebb9f2d | ||
|
|
0468e10854 | ||
|
|
29b9351a9a | ||
|
|
6e51fe7bda | ||
|
|
1092009f1b | ||
|
|
3ecd7c8d08 | ||
|
|
f5d46c4983 | ||
|
|
1a6be8daa5 | ||
|
|
17963e0adb | ||
|
|
33d43d773d | ||
|
|
dd8be91b33 | ||
|
|
c62fb96b58 | ||
|
|
93356592e8 | ||
|
|
488daea476 | ||
|
|
0196d9ed6a | ||
|
|
8c449dce0e | ||
|
|
a3f3355359 | ||
|
|
f7fbd63f7e | ||
|
|
cfb4b54763 | ||
|
|
4cd9204c19 | ||
|
|
a12d617e69 | ||
|
|
058675f072 | ||
|
|
416c1638a9 | ||
|
|
214f8379bf | ||
|
|
24a2e32339 | ||
|
|
2057e53ee2 | ||
|
|
2b1ef6ea31 | ||
|
|
b171f3a68a | ||
|
|
052b73713e | ||
|
|
82710ddf17 | ||
|
|
74b8899be7 | ||
|
|
2cf5dcd6fd | ||
|
|
453c4e2895 | ||
|
|
79ddb51a74 | ||
|
|
df72fd8622 | ||
|
|
cb1461704b |
284 changed files with 17008 additions and 9540 deletions
|
|
@ -46,3 +46,10 @@ GOOGLE_RECAPTCHA_PRIVATE=6LeQxHoUAAAAAOudkLY90DerM_ZtlaFfzTlJJvIo
|
||||||
GOOGLE_RECAPTCHA_VERSION=2
|
GOOGLE_RECAPTCHA_VERSION=2
|
||||||
# - MAPS
|
# - MAPS
|
||||||
GOOGLE_MAPS_KEY=
|
GOOGLE_MAPS_KEY=
|
||||||
|
|
||||||
|
# UWIL ADMIN SECURE
|
||||||
|
# - LIST SEPARATED WITH ',' (Required)
|
||||||
|
UWIL_ADMIN_SECURE_CIDR_LIST=""
|
||||||
|
# - LIST SEPARATED WITH ',' (Optional)
|
||||||
|
UWIL_ADMIN_SECURE_CIDR_PROJECT_ALLOWED_LIST=""
|
||||||
|
|
||||||
|
|
|
||||||
2
.husky/commit-msg
Normal file
2
.husky/commit-msg
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
#!/bin/sh
|
||||||
|
npx commitlint --config node_modules/@uwil/husky-config/commitlint.config.js --edit $1
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
FROM registry.s-web.fr/ldc-web/projets/ldc-web-images-docker/ldcweb-production-8.2:latest
|
FROM registry.s-web.fr/ldc-web/projets/ldc-web-images-docker/uwil-production-8.5:${PHP_8_5_TAG}
|
||||||
COPY --chown=www-data:www-data . /app/srcs
|
COPY --chown=www-data:www-data . /app/srcs
|
||||||
COPY --chown=www-data:www-data ./public/build /app/srcs/public/build
|
COPY --chown=www-data:www-data ./public/build /app/srcs/public/build
|
||||||
COPY --chown=www-data:www-data ./vendor /app/srcs/vendor
|
COPY --chown=www-data:www-data ./vendor /app/srcs/vendor
|
||||||
USER root
|
USER root
|
||||||
RUN chmod -R 755 /app/srcs/storage
|
RUN chmod -R 755 /app/srcs/storage
|
||||||
USER www-data
|
USER www-data
|
||||||
|
|
|
||||||
|
|
@ -26,28 +26,28 @@ class CreateAdmin extends Command
|
||||||
/**
|
/**
|
||||||
* The firstname of the new user.
|
* The firstname of the new user.
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string|null
|
||||||
*/
|
*/
|
||||||
protected $firstname;
|
protected $firstname;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The lastname of the new user.
|
* The lastname of the new user.
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string|null
|
||||||
*/
|
*/
|
||||||
protected $lastname;
|
protected $lastname;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The email of the new user.
|
* The email of the new user.
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string|null
|
||||||
*/
|
*/
|
||||||
protected $email;
|
protected $email;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The password of the new user.
|
* The password of the new user.
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string|null
|
||||||
*/
|
*/
|
||||||
protected $password;
|
protected $password;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace App\Console;
|
namespace App\Console;
|
||||||
|
|
||||||
|
use App\Jobs\NewsStatusUpdate;
|
||||||
use App\Jobs\SlidersStatusUpdate;
|
use App\Jobs\SlidersStatusUpdate;
|
||||||
use Illuminate\Console\Scheduling\Schedule;
|
use Illuminate\Console\Scheduling\Schedule;
|
||||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||||
|
|
@ -17,6 +18,7 @@ class Kernel extends ConsoleKernel
|
||||||
protected function schedule(Schedule $schedule)
|
protected function schedule(Schedule $schedule)
|
||||||
{
|
{
|
||||||
$schedule->job(SlidersStatusUpdate::class)->everyMinute();
|
$schedule->job(SlidersStatusUpdate::class)->everyMinute();
|
||||||
|
$schedule->job(NewsStatusUpdate::class)->everyMinute();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -18,11 +18,11 @@ enum ColorsEnum: int
|
||||||
* Custom added colors definition
|
* Custom added colors definition
|
||||||
*/
|
*/
|
||||||
private const COLORS = [
|
private const COLORS = [
|
||||||
self::redwine->name => 'rgb(165 25 60)',
|
self::redwine->name => 'rgb(165 25 60)',
|
||||||
self::orange->name => 'rgb(240 165 0)',
|
self::orange->name => 'rgb(240 165 0)',
|
||||||
self::blue->name => 'rgb(95 155 210)',
|
self::blue->name => 'rgb(95 155 210)',
|
||||||
self::lightgreen->name => 'rgb(180 190 0)',
|
self::lightgreen->name => 'rgb(180 190 0)',
|
||||||
self::brown->name => 'rgb(95 40 45)',
|
self::brown->name => 'rgb(95 40 45)',
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -21,10 +21,7 @@ enum InputType: int
|
||||||
case string = 11;
|
case string = 11;
|
||||||
case text = 12;
|
case text = 12;
|
||||||
case url = 13;
|
case url = 13;
|
||||||
/** Vimeo only */
|
case videoVimeo = 14;
|
||||||
case videoVimeo = 14;
|
case videoYoutube = 15;
|
||||||
/** Youtube only */
|
case video = 16;
|
||||||
case videoYoutube = 15;
|
|
||||||
/** Youtube or Vimeo. */
|
|
||||||
case video = 16;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,19 +4,31 @@ namespace App\Enums\Products;
|
||||||
|
|
||||||
use App\Traits\Enums\BaseEnum;
|
use App\Traits\Enums\BaseEnum;
|
||||||
|
|
||||||
enum CertificationsEnum : int
|
enum CertificationsEnum: int
|
||||||
{
|
{
|
||||||
use BaseEnum;
|
use BaseEnum;
|
||||||
|
|
||||||
case haltungsform3 = 3;
|
case haltungsform3 = 3;
|
||||||
|
case haltungsform4 = 4;
|
||||||
case ecc = 5;
|
case ecc = 5;
|
||||||
|
case nutriscoreA = 6;
|
||||||
|
case nutriscoreB = 7;
|
||||||
|
case nutriscoreC = 8;
|
||||||
|
case nutriscoreD = 9;
|
||||||
|
case nutriscoreE = 10;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Custom added images definition
|
* Custom added images definition
|
||||||
*/
|
*/
|
||||||
private const IMAGES = [
|
private const IMAGES = [
|
||||||
self::haltungsform3->name => "haltungsform3.png",
|
self::haltungsform3->name => "haltungsform3.png",
|
||||||
self::ecc->name => "ECC-Logo-green.svg",
|
self::haltungsform4->name => "haltungsform4.png",
|
||||||
|
self::ecc->name => "ECC-Logo-green.svg",
|
||||||
|
self::nutriscoreA->name => "nutriscore-a.png",
|
||||||
|
self::nutriscoreB->name => "nutriscore-b.png",
|
||||||
|
self::nutriscoreC->name => "nutriscore-c.png",
|
||||||
|
self::nutriscoreD->name => "nutriscore-d.png",
|
||||||
|
self::nutriscoreE->name => "nutriscore-e.png",
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -19,12 +19,12 @@ enum PictoEnum : int
|
||||||
* Custom added images definition
|
* Custom added images definition
|
||||||
*/
|
*/
|
||||||
private const IMAGES = [
|
private const IMAGES = [
|
||||||
self::chicken->name => "chicken.png",
|
self::chicken->name => "chicken.png",
|
||||||
self::duck->name => "duck.png",
|
self::duck->name => "duck.png",
|
||||||
self::turkey->name => "turkey.png",
|
self::turkey->name => "turkey.png",
|
||||||
self::soupchicken->name => "soupchicken.png",
|
self::soupchicken->name => "soupchicken.png",
|
||||||
self::guineafowl->name => "guineafowl.png",
|
self::guineafowl->name => "guineafowl.png",
|
||||||
self::goose->name => "goose.png",
|
self::goose->name => "goose.png",
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
56
app/Enums/StaticPageType.php
Normal file
56
app/Enums/StaticPageType.php
Normal file
|
|
@ -0,0 +1,56 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Enums;
|
||||||
|
|
||||||
|
use App\Traits\Enums\BaseEnum;
|
||||||
|
|
||||||
|
enum StaticPageType: int
|
||||||
|
{
|
||||||
|
use BaseEnum;
|
||||||
|
|
||||||
|
case contact = 1;
|
||||||
|
case legals = 2;
|
||||||
|
case confidentiality = 3;
|
||||||
|
case home = 4;
|
||||||
|
case products = 5;
|
||||||
|
case product = 6;
|
||||||
|
case recipes = 7;
|
||||||
|
case recipe = 8;
|
||||||
|
case newsPlural = 9;
|
||||||
|
case newsSingular = 10;
|
||||||
|
case concept = 11;
|
||||||
|
case store = 12;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Optionnal labels definition.
|
||||||
|
*
|
||||||
|
* @phpstan-ignore-next-line
|
||||||
|
*/
|
||||||
|
private const LABELS = [
|
||||||
|
self::contact->name => 'enums.static_page_type.contact',
|
||||||
|
self::legals->name => 'enums.static_page_type.legals',
|
||||||
|
self::confidentiality->name => 'enums.static_page_type.confidentiality',
|
||||||
|
self::home->name => 'enums.static_page_type.home',
|
||||||
|
self::products->name => 'enums.static_page_type.products',
|
||||||
|
self::product->name => 'enums.static_page_type.product',
|
||||||
|
self::recipes->name => 'enums.static_page_type.recipes',
|
||||||
|
self::recipe->name => 'enums.static_page_type.recipe',
|
||||||
|
self::newsPlural->name => 'enums.static_page_type.newsPlural',
|
||||||
|
self::newsSingular->name => 'enums.static_page_type.newsSingular',
|
||||||
|
self::concept->name => 'enums.static_page_type.concept',
|
||||||
|
self::store->name => 'enums.static_page_type.store',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all editable pages.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function getEditableContentPages(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
self::legals,
|
||||||
|
self::confidentiality,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -21,9 +21,9 @@ class ConceptController extends Controller
|
||||||
* Display a listing of the resource.
|
* Display a listing of the resource.
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Http\Request $request
|
* @param \Illuminate\Http\Request $request
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Contracts\View\View
|
||||||
*/
|
*/
|
||||||
public function index(Request $request)
|
public function index(Request $request): \Illuminate\Contracts\View\View
|
||||||
{
|
{
|
||||||
/** @var \Illuminate\Database\Eloquent\Builder $concepts */
|
/** @var \Illuminate\Database\Eloquent\Builder $concepts */
|
||||||
$concepts = Concept::query();
|
$concepts = Concept::query();
|
||||||
|
|
@ -51,9 +51,9 @@ class ConceptController extends Controller
|
||||||
/**
|
/**
|
||||||
* Show the form for creating a new resource.
|
* Show the form for creating a new resource.
|
||||||
*
|
*
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Contracts\View\View|\Illuminate\Http\RedirectResponse
|
||||||
*/
|
*/
|
||||||
public function create()
|
public function create(): \Illuminate\Contracts\View\View|\Illuminate\Http\RedirectResponse
|
||||||
{
|
{
|
||||||
if (Concept::count() === 8) {
|
if (Concept::count() === 8) {
|
||||||
return back()
|
return back()
|
||||||
|
|
@ -61,7 +61,7 @@ class ConceptController extends Controller
|
||||||
'error',
|
'error',
|
||||||
trans(
|
trans(
|
||||||
'You already created 8 :models. Please delete or edit an existing one.',
|
'You already created 8 :models. Please delete or edit an existing one.',
|
||||||
['models' => trans('models.classes.concepts')]
|
['models' => Str::of(trans('models.classes.concept'))->plural()]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -73,9 +73,9 @@ class ConceptController extends Controller
|
||||||
* Store a newly created resource in storage.
|
* Store a newly created resource in storage.
|
||||||
*
|
*
|
||||||
* @param \App\Http\Requests\Bo\Concepts\StoreConceptRequest $request
|
* @param \App\Http\Requests\Bo\Concepts\StoreConceptRequest $request
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\RedirectResponse
|
||||||
*/
|
*/
|
||||||
public function store(StoreConceptRequest $request)
|
public function store(StoreConceptRequest $request): \Illuminate\Http\RedirectResponse
|
||||||
{
|
{
|
||||||
return DB::transaction(function () use ($request) {
|
return DB::transaction(function () use ($request) {
|
||||||
$concept = new Concept();
|
$concept = new Concept();
|
||||||
|
|
@ -90,14 +90,14 @@ class ConceptController extends Controller
|
||||||
->route('bo.concepts.edit', $concept)
|
->route('bo.concepts.edit', $concept)
|
||||||
->with('success', trans(
|
->with('success', trans(
|
||||||
'crud.messages.has_been_created',
|
'crud.messages.has_been_created',
|
||||||
['model' => Str::singular(trans('models.classes.concepts'))]
|
['model' => trans('models.classes.concept')]
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
return redirect()
|
return redirect()
|
||||||
->back()
|
->back()
|
||||||
->with('error', trans(
|
->with('error', trans(
|
||||||
'crud.messages.cannot_be_created',
|
'crud.messages.cannot_be_created',
|
||||||
['model' => Str::singular(trans('models.classes.concepts'))]
|
['model' => trans('models.classes.concept')]
|
||||||
));
|
));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -106,9 +106,9 @@ class ConceptController extends Controller
|
||||||
* Show the form for editing the specified resource.
|
* Show the form for editing the specified resource.
|
||||||
*
|
*
|
||||||
* @param \App\Models\Concept $concept
|
* @param \App\Models\Concept $concept
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Contracts\View\View
|
||||||
*/
|
*/
|
||||||
public function edit(Concept $concept)
|
public function edit(Concept $concept): \Illuminate\Contracts\View\View
|
||||||
{
|
{
|
||||||
return view('bo.pages.concepts.edit', [
|
return view('bo.pages.concepts.edit', [
|
||||||
'conceptModel' => $concept
|
'conceptModel' => $concept
|
||||||
|
|
@ -120,9 +120,9 @@ class ConceptController extends Controller
|
||||||
*
|
*
|
||||||
* @param \App\Http\Requests\Bo\Concepts\UpdateConceptRequest $request
|
* @param \App\Http\Requests\Bo\Concepts\UpdateConceptRequest $request
|
||||||
* @param \App\Models\Concept $concept
|
* @param \App\Models\Concept $concept
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\RedirectResponse
|
||||||
*/
|
*/
|
||||||
public function update(UpdateConceptRequest $request, Concept $concept)
|
public function update(UpdateConceptRequest $request, Concept $concept): \Illuminate\Http\RedirectResponse
|
||||||
{
|
{
|
||||||
return DB::transaction(function () use ($request, $concept) {
|
return DB::transaction(function () use ($request, $concept) {
|
||||||
$concept->fill(array_replace_recursive(
|
$concept->fill(array_replace_recursive(
|
||||||
|
|
@ -135,14 +135,14 @@ class ConceptController extends Controller
|
||||||
->route('bo.concepts.edit', $concept)
|
->route('bo.concepts.edit', $concept)
|
||||||
->with('success', trans(
|
->with('success', trans(
|
||||||
'crud.messages.has_been_updated',
|
'crud.messages.has_been_updated',
|
||||||
['model' => Str::singular(trans('models.classes.concepts'))]
|
['model' => trans('models.classes.concept')]
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
return redirect()
|
return redirect()
|
||||||
->back()
|
->back()
|
||||||
->with('error', trans(
|
->with('error', trans(
|
||||||
'crud.messages.cannot_be_updated',
|
'crud.messages.cannot_be_updated',
|
||||||
['model' => Str::singular(trans('models.classes.concepts'))]
|
['model' => trans('models.classes.concept')]
|
||||||
));
|
));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -151,23 +151,23 @@ class ConceptController extends Controller
|
||||||
* Remove the specified resource from storage.
|
* Remove the specified resource from storage.
|
||||||
*
|
*
|
||||||
* @param \App\Models\Concept $concept
|
* @param \App\Models\Concept $concept
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\RedirectResponse
|
||||||
*/
|
*/
|
||||||
public function destroy(Concept $concept)
|
public function destroy(Concept $concept): \Illuminate\Http\RedirectResponse
|
||||||
{
|
{
|
||||||
if ($concept->deleteOrFail()) {
|
if ($concept->deleteOrFail()) {
|
||||||
return redirect()
|
return redirect()
|
||||||
->route('bo.concepts.index')
|
->route('bo.concepts.index')
|
||||||
->with('success', trans(
|
->with('success', trans(
|
||||||
'crud.messages.has_been_deleted',
|
'crud.messages.has_been_deleted',
|
||||||
['model' => Str::singular(trans('models.classes.concepts'))]
|
['model' => trans('models.classes.concept')]
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
return redirect()
|
return redirect()
|
||||||
->back()
|
->back()
|
||||||
->with('error', trans(
|
->with('error', trans(
|
||||||
':crud.messages.cannot_be_deleted',
|
':crud.messages.cannot_be_deleted',
|
||||||
['model' => Str::singular(trans('models.classes.concepts'))]
|
['model' => trans('models.classes.concept')]
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,20 +6,16 @@ use App\Http\Controllers\Controller;
|
||||||
use App\Http\Requests\Bo\Homes\UpdateHomeRequest;
|
use App\Http\Requests\Bo\Homes\UpdateHomeRequest;
|
||||||
use App\Models\Home;
|
use App\Models\Home;
|
||||||
use App\Models\Product;
|
use App\Models\Product;
|
||||||
use App\Traits\Requests\HasPicture;
|
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Str;
|
|
||||||
|
|
||||||
class HomeController extends Controller
|
class HomeController extends Controller
|
||||||
{
|
{
|
||||||
use HasPicture;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display a listing of the resource.
|
* Display a listing of the resource.
|
||||||
*
|
*
|
||||||
* @return \Illuminate\Contracts\View\View|\Illuminate\Contracts\View\Factory
|
* @return \Illuminate\Contracts\View\View
|
||||||
*/
|
*/
|
||||||
public function edit()
|
public function edit(): \Illuminate\Contracts\View\View
|
||||||
{
|
{
|
||||||
$homeModel = Home::query()->firstOrFail();
|
$homeModel = Home::query()->firstOrFail();
|
||||||
$products = Product::query()->where('status', true)->orderBy('label', 'ASC')->get();
|
$products = Product::query()->where('status', true)->orderBy('label', 'ASC')->get();
|
||||||
|
|
@ -32,9 +28,9 @@ class HomeController extends Controller
|
||||||
*
|
*
|
||||||
* @param \App\Http\Requests\Bo\Homes\UpdateHomeRequest $request
|
* @param \App\Http\Requests\Bo\Homes\UpdateHomeRequest $request
|
||||||
* @param \App\Models\Home $home
|
* @param \App\Models\Home $home
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\RedirectResponse
|
||||||
*/
|
*/
|
||||||
public function update(UpdateHomeRequest $request, Home $home)
|
public function update(UpdateHomeRequest $request, Home $home): \Illuminate\Http\RedirectResponse
|
||||||
{
|
{
|
||||||
return DB::transaction(function () use ($request, $home) {
|
return DB::transaction(function () use ($request, $home) {
|
||||||
$data = $request->validated();
|
$data = $request->validated();
|
||||||
|
|
@ -44,12 +40,12 @@ class HomeController extends Controller
|
||||||
->route('bo.homes.edit', $home)
|
->route('bo.homes.edit', $home)
|
||||||
->with('success', trans(
|
->with('success', trans(
|
||||||
'crud.messages.has_been_updated',
|
'crud.messages.has_been_updated',
|
||||||
['model' => Str::singular(trans('models.classes.homes'))]
|
['model' => trans('models.classes.home')]
|
||||||
));
|
));
|
||||||
} //end if
|
} //end if
|
||||||
return back()->with('success', trans(
|
return back()->with('success', trans(
|
||||||
'crud.messages.cannot_be_updated',
|
'crud.messages.cannot_be_updated',
|
||||||
['model' => Str::singular(trans('models.classes.homes'))]
|
['model' => trans('models.classes.home')]
|
||||||
));
|
));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
163
app/Http/Controllers/Bo/NewsController.php
Normal file
163
app/Http/Controllers/Bo/NewsController.php
Normal file
|
|
@ -0,0 +1,163 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Bo;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Http\Requests\Bo\News\StoreNewsRequest;
|
||||||
|
use App\Http\Requests\Bo\News\UpdateNewsRequest;
|
||||||
|
use App\Models\News;
|
||||||
|
use App\Traits\Controllers\ChangesModelOrder;
|
||||||
|
use App\Traits\Controllers\UpdateModelStatus;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
|
class NewsController extends Controller
|
||||||
|
{
|
||||||
|
use ChangesModelOrder;
|
||||||
|
use UpdateModelStatus;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 $news */
|
||||||
|
$news = News::query();
|
||||||
|
|
||||||
|
if ($request->search) {
|
||||||
|
$this->searchQuery(
|
||||||
|
$news,
|
||||||
|
$request->search,
|
||||||
|
null,
|
||||||
|
'seo_title',
|
||||||
|
'title',
|
||||||
|
'subtitle',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->sortQuery($news);
|
||||||
|
$searchFields = trans('SEO title, Title, subtitle');
|
||||||
|
|
||||||
|
$newsListModels = $news->paginate(10);
|
||||||
|
|
||||||
|
return view('bo.pages.news.index', compact('newsListModels', 'searchFields'));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show the form for creating a new resource.
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Contracts\View\View
|
||||||
|
*/
|
||||||
|
public function create(): \Illuminate\Contracts\View\View
|
||||||
|
{
|
||||||
|
return view('bo.pages.news.create');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store a newly created resource in storage.
|
||||||
|
*
|
||||||
|
* @param \App\Http\Requests\Bo\News\StoreNewsRequest $request
|
||||||
|
* @return \Illuminate\Http\RedirectResponse
|
||||||
|
*/
|
||||||
|
public function store(StoreNewsRequest $request): \Illuminate\Http\RedirectResponse
|
||||||
|
{
|
||||||
|
return DB::transaction(function () use ($request) {
|
||||||
|
$news = new News();
|
||||||
|
$news->data = News::getEmptyData();
|
||||||
|
$news->fill(array_replace_recursive(
|
||||||
|
\json_decode(\json_encode($news->toArray()), true),
|
||||||
|
$request->validated()
|
||||||
|
));
|
||||||
|
|
||||||
|
if ($news->saveOrFail()) {
|
||||||
|
return redirect()
|
||||||
|
->route('bo.news.edit', $news)
|
||||||
|
->with('success', trans(
|
||||||
|
'crud.messages.has_been_created',
|
||||||
|
['model' => Str::singular(trans('models.classes.news'))]
|
||||||
|
));
|
||||||
|
}
|
||||||
|
return redirect()
|
||||||
|
->back()
|
||||||
|
->with('error', trans(
|
||||||
|
'crud.messages.cannot_be_created',
|
||||||
|
['model' => Str::singular(trans('models.classes.news'))]
|
||||||
|
));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show the form for editing the specified resource.
|
||||||
|
*
|
||||||
|
* @param \App\Models\News $news
|
||||||
|
* @return \Illuminate\Contracts\View\View
|
||||||
|
*/
|
||||||
|
public function edit(News $news): \Illuminate\Contracts\View\View
|
||||||
|
{
|
||||||
|
return view('bo.pages.news.edit', [
|
||||||
|
'newsModel' => $news
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the specified resource in storage.
|
||||||
|
*
|
||||||
|
* @param \App\Http\Requests\Bo\News\UpdateNewsRequest $request
|
||||||
|
* @param \App\Models\News $news
|
||||||
|
* @return \Illuminate\Http\RedirectResponse
|
||||||
|
*/
|
||||||
|
public function update(UpdateNewsRequest $request, News $news): \Illuminate\Http\RedirectResponse
|
||||||
|
{
|
||||||
|
return DB::transaction(function () use ($request, $news) {
|
||||||
|
$news->fill(array_replace_recursive(
|
||||||
|
\json_decode(\json_encode($news->toArray()), true),
|
||||||
|
$request->validated()
|
||||||
|
));
|
||||||
|
$news->locales = $request->locales;
|
||||||
|
if ($news->saveOrFail()) {
|
||||||
|
return redirect()
|
||||||
|
->route('bo.news.edit', $news)
|
||||||
|
->with('success', trans(
|
||||||
|
'crud.messages.has_been_updated',
|
||||||
|
['model' => Str::singular(trans('models.classes.news'))]
|
||||||
|
));
|
||||||
|
}
|
||||||
|
return redirect()
|
||||||
|
->back()
|
||||||
|
->with('error', trans(
|
||||||
|
'crud.messages.cannot_be_updated',
|
||||||
|
['model' => Str::singular(trans('models.classes.news'))]
|
||||||
|
));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove the specified resource from storage.
|
||||||
|
*
|
||||||
|
* @param \App\Models\News $news
|
||||||
|
* @return \Illuminate\Http\RedirectResponse
|
||||||
|
*/
|
||||||
|
public function destroy(News $news): \Illuminate\Http\RedirectResponse
|
||||||
|
{
|
||||||
|
if ($news->deleteOrFail()) {
|
||||||
|
return redirect()
|
||||||
|
->route('bo.news.index')
|
||||||
|
->with('success', trans(
|
||||||
|
'crud.messages.has_been_deleted',
|
||||||
|
['model' => Str::singular(trans('models.classes.news'))]
|
||||||
|
));
|
||||||
|
}
|
||||||
|
return redirect()
|
||||||
|
->back()
|
||||||
|
->with('error', trans(
|
||||||
|
':crud.messages.cannot_be_deleted',
|
||||||
|
['model' => Str::singular(trans('models.classes.news'))]
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -10,24 +10,21 @@ use App\Models\Product;
|
||||||
use App\Models\Range;
|
use App\Models\Range;
|
||||||
use App\Traits\Controllers\ChangesModelOrder;
|
use App\Traits\Controllers\ChangesModelOrder;
|
||||||
use App\Traits\Controllers\UpdateModelStatus;
|
use App\Traits\Controllers\UpdateModelStatus;
|
||||||
use App\Traits\Requests\HasPicture;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Contracts\Database\Eloquent\Builder;
|
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Str;
|
|
||||||
|
|
||||||
class ProductController extends Controller
|
class ProductController extends Controller
|
||||||
{
|
{
|
||||||
use ChangesModelOrder;
|
use ChangesModelOrder;
|
||||||
use HasPicture;
|
|
||||||
use UpdateModelStatus;
|
use UpdateModelStatus;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display a listing of the resource.
|
* Display a listing of the resource.
|
||||||
*
|
*
|
||||||
* @param \App\Http\Requests\ProductIndexFilterRequest $request
|
* @param \App\Http\Requests\ProductIndexFilterRequest $request
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Contracts\View\View
|
||||||
*/
|
*/
|
||||||
public function index(ProductIndexFilterRequest $request)
|
public function index(ProductIndexFilterRequest $request): \Illuminate\Contracts\View\View
|
||||||
{
|
{
|
||||||
/** @var \Illuminate\Database\Eloquent\Builder $product */
|
/** @var \Illuminate\Database\Eloquent\Builder $product */
|
||||||
$product = Product::query();
|
$product = Product::query();
|
||||||
|
|
@ -60,9 +57,9 @@ class ProductController extends Controller
|
||||||
/**
|
/**
|
||||||
* Show the form for creating a new resource.
|
* Show the form for creating a new resource.
|
||||||
*
|
*
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Contracts\View\View
|
||||||
*/
|
*/
|
||||||
public function create()
|
public function create(): \Illuminate\Contracts\View\View
|
||||||
{
|
{
|
||||||
$rangeModels = Range::orderBy('label', 'ASC')->get();
|
$rangeModels = Range::orderBy('label', 'ASC')->get();
|
||||||
|
|
||||||
|
|
@ -73,14 +70,14 @@ class ProductController extends Controller
|
||||||
* Store a newly created resource in storage.
|
* Store a newly created resource in storage.
|
||||||
*
|
*
|
||||||
* @param \App\Http\Requests\Bo\Products\StoreProductRequest $request
|
* @param \App\Http\Requests\Bo\Products\StoreProductRequest $request
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\RedirectResponse
|
||||||
*/
|
*/
|
||||||
public function store(StoreProductRequest $request)
|
public function store(StoreProductRequest $request): \Illuminate\Http\RedirectResponse
|
||||||
{
|
{
|
||||||
return DB::transaction(function () use ($request) {
|
return DB::transaction(function () use ($request) {
|
||||||
$product = new Product();
|
$product = new Product();
|
||||||
$tmpNutrionnalValues = \collect($request->validated()['nutritionnal_values']);
|
$tmpNutrionnalValues = $request->validated()['nutritionnal_values'];
|
||||||
$tmpList = \collect($request->validated()['list']);
|
$tmpList = $request->validated()['list'];
|
||||||
$product->fill($request->validated());
|
$product->fill($request->validated());
|
||||||
$product->nutritionnal_values = $tmpNutrionnalValues;
|
$product->nutritionnal_values = $tmpNutrionnalValues;
|
||||||
$product->list = $tmpList;
|
$product->list = $tmpList;
|
||||||
|
|
@ -90,14 +87,14 @@ class ProductController extends Controller
|
||||||
->route('bo.products.edit', $product)
|
->route('bo.products.edit', $product)
|
||||||
->with('success', trans(
|
->with('success', trans(
|
||||||
'crud.messages.has_been_created',
|
'crud.messages.has_been_created',
|
||||||
['model' => Str::singular(trans('models.classes.products'))]
|
['model' => trans('models.classes.product')]
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
return redirect()
|
return redirect()
|
||||||
->back()
|
->back()
|
||||||
->with('error', trans(
|
->with('error', trans(
|
||||||
'crud.messages.cannot_be_created',
|
'crud.messages.cannot_be_created',
|
||||||
['model' => Str::singular(trans('models.classes.products'))]
|
['model' => trans('models.classes.product')]
|
||||||
));
|
));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -106,9 +103,9 @@ class ProductController extends Controller
|
||||||
* Display a listing of the resource.
|
* Display a listing of the resource.
|
||||||
*
|
*
|
||||||
* @param \App\Models\Product $product
|
* @param \App\Models\Product $product
|
||||||
* @return \Illuminate\Contracts\View\View|\Illuminate\Contracts\View\Factory
|
* @return \Illuminate\Contracts\View\View
|
||||||
*/
|
*/
|
||||||
public function edit(Product $product)
|
public function edit(Product $product): \Illuminate\Contracts\View\View
|
||||||
{
|
{
|
||||||
$rangeModels = Range::orderBy('label', 'ASC')->get();
|
$rangeModels = Range::orderBy('label', 'ASC')->get();
|
||||||
|
|
||||||
|
|
@ -123,13 +120,13 @@ class ProductController extends Controller
|
||||||
*
|
*
|
||||||
* @param \App\Http\Requests\Bo\Products\UpdateProductRequest $request
|
* @param \App\Http\Requests\Bo\Products\UpdateProductRequest $request
|
||||||
* @param \App\Models\Product $product
|
* @param \App\Models\Product $product
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\RedirectResponse
|
||||||
*/
|
*/
|
||||||
public function update(UpdateProductRequest $request, Product $product)
|
public function update(UpdateProductRequest $request, Product $product): \Illuminate\Http\RedirectResponse
|
||||||
{
|
{
|
||||||
return DB::transaction(function () use ($request, $product) {
|
return DB::transaction(function () use ($request, $product) {
|
||||||
$tmpNutrionnalValues = \collect($request->validated()['nutritionnal_values']);
|
$tmpNutrionnalValues = $request->validated()['nutritionnal_values'];
|
||||||
$tmpList = \collect($request->validated()['list']);
|
$tmpList = $request->validated()['list'];
|
||||||
$product->fill($request->validated());
|
$product->fill($request->validated());
|
||||||
$product->nutritionnal_values = $tmpNutrionnalValues;
|
$product->nutritionnal_values = $tmpNutrionnalValues;
|
||||||
$product->list = $tmpList;
|
$product->list = $tmpList;
|
||||||
|
|
@ -138,14 +135,14 @@ class ProductController extends Controller
|
||||||
->route('bo.products.edit', $product)
|
->route('bo.products.edit', $product)
|
||||||
->with('success', trans(
|
->with('success', trans(
|
||||||
'crud.messages.has_been_updated',
|
'crud.messages.has_been_updated',
|
||||||
['model' => Str::singular(trans('models.classes.products'))]
|
['model' => trans('models.classes.product')]
|
||||||
));
|
));
|
||||||
} //end if
|
} //end if
|
||||||
return redirect()
|
return redirect()
|
||||||
->back()
|
->back()
|
||||||
->with('error', trans(
|
->with('error', trans(
|
||||||
'crud.messages.cannot_be_updated',
|
'crud.messages.cannot_be_updated',
|
||||||
['model' => Str::singular(trans('models.classes.products'))]
|
['model' => trans('models.classes.product')]
|
||||||
));
|
));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -154,9 +151,9 @@ class ProductController extends Controller
|
||||||
* Remove the specified resource from storage.
|
* Remove the specified resource from storage.
|
||||||
*
|
*
|
||||||
* @param \App\Models\Product $product
|
* @param \App\Models\Product $product
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\RedirectResponse
|
||||||
*/
|
*/
|
||||||
public function destroy(Product $product)
|
public function destroy(Product $product): \Illuminate\Http\RedirectResponse
|
||||||
{
|
{
|
||||||
return DB::transaction(function () use ($product) {
|
return DB::transaction(function () use ($product) {
|
||||||
$product->recipes()->detach();
|
$product->recipes()->detach();
|
||||||
|
|
@ -165,14 +162,14 @@ class ProductController extends Controller
|
||||||
->route('bo.products.index')
|
->route('bo.products.index')
|
||||||
->with('success', trans(
|
->with('success', trans(
|
||||||
'crud.messages.has_been_deleted',
|
'crud.messages.has_been_deleted',
|
||||||
['model' => Str::singular(trans('models.classes.products'))]
|
['model' => trans('models.classes.product')]
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
return redirect()
|
return redirect()
|
||||||
->back()
|
->back()
|
||||||
->with('error', trans(
|
->with('error', trans(
|
||||||
':crud.messages.cannot_be_deleted',
|
':crud.messages.cannot_be_deleted',
|
||||||
['model' => Str::singular(trans('models.classes.products'))]
|
['model' => trans('models.classes.product')]
|
||||||
));
|
));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,24 +8,21 @@ use App\Http\Requests\Bo\Ranges\UpdateRangeRequest;
|
||||||
use App\Models\Range;
|
use App\Models\Range;
|
||||||
use App\Traits\Controllers\UpdateModelStatus;
|
use App\Traits\Controllers\UpdateModelStatus;
|
||||||
use App\Traits\Controllers\ChangesModelOrder;
|
use App\Traits\Controllers\ChangesModelOrder;
|
||||||
use App\Traits\Requests\HasPicture;
|
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Str;
|
|
||||||
|
|
||||||
class RangeController extends Controller
|
class RangeController extends Controller
|
||||||
{
|
{
|
||||||
use ChangesModelOrder;
|
use ChangesModelOrder;
|
||||||
use HasPicture;
|
|
||||||
use UpdateModelStatus;
|
use UpdateModelStatus;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display a listing of the resource.
|
* Display a listing of the resource.
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Http\Request $request
|
* @param \Illuminate\Http\Request $request
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Contracts\View\View
|
||||||
*/
|
*/
|
||||||
public function index(Request $request)
|
public function index(Request $request): \Illuminate\Contracts\View\View
|
||||||
{
|
{
|
||||||
/** @var \Illuminate\Database\Eloquent\Builder $range */
|
/** @var \Illuminate\Database\Eloquent\Builder $range */
|
||||||
$range = Range::query();
|
$range = Range::query();
|
||||||
|
|
@ -50,9 +47,9 @@ class RangeController extends Controller
|
||||||
/**
|
/**
|
||||||
* Show the form for creating a new resource.
|
* Show the form for creating a new resource.
|
||||||
*
|
*
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Contracts\View\View
|
||||||
*/
|
*/
|
||||||
public function create()
|
public function create(): \Illuminate\Contracts\View\View
|
||||||
{
|
{
|
||||||
return view('bo.pages.ranges.create');
|
return view('bo.pages.ranges.create');
|
||||||
}
|
}
|
||||||
|
|
@ -61,9 +58,9 @@ class RangeController extends Controller
|
||||||
* Store a newly created resource in storage.
|
* Store a newly created resource in storage.
|
||||||
*
|
*
|
||||||
* @param \App\Http\Requests\Bo\Ranges\StoreRangeRequest $request
|
* @param \App\Http\Requests\Bo\Ranges\StoreRangeRequest $request
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\RedirectResponse
|
||||||
*/
|
*/
|
||||||
public function store(StoreRangeRequest $request)
|
public function store(StoreRangeRequest $request): \Illuminate\Http\RedirectResponse
|
||||||
{
|
{
|
||||||
return DB::transaction(function () use ($request) {
|
return DB::transaction(function () use ($request) {
|
||||||
$range = new Range();
|
$range = new Range();
|
||||||
|
|
@ -74,14 +71,14 @@ class RangeController extends Controller
|
||||||
->route('bo.ranges.edit', $range)
|
->route('bo.ranges.edit', $range)
|
||||||
->with('success', trans(
|
->with('success', trans(
|
||||||
'crud.messages.has_been_created',
|
'crud.messages.has_been_created',
|
||||||
['model' => Str::singular(trans('models.classes.ranges'))]
|
['model' => trans('models.classes.range')]
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
return redirect()
|
return redirect()
|
||||||
->back()
|
->back()
|
||||||
->with('error', trans(
|
->with('error', trans(
|
||||||
'crud.messages.cannot_be_created',
|
'crud.messages.cannot_be_created',
|
||||||
['model' => Str::singular(trans('models.classes.ranges'))]
|
['model' => trans('models.classes.range')]
|
||||||
));
|
));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -90,9 +87,9 @@ class RangeController extends Controller
|
||||||
* Display a listing of the resource.
|
* Display a listing of the resource.
|
||||||
*
|
*
|
||||||
* @param \App\Models\Range $range
|
* @param \App\Models\Range $range
|
||||||
* @return \Illuminate\Contracts\View\View|\Illuminate\Contracts\View\Factory
|
* @return \Illuminate\Contracts\View\View
|
||||||
*/
|
*/
|
||||||
public function edit(Range $range)
|
public function edit(Range $range): \Illuminate\Contracts\View\View
|
||||||
{
|
{
|
||||||
return view('bo.pages.ranges.edit', ['rangeModel' => $range]);
|
return view('bo.pages.ranges.edit', ['rangeModel' => $range]);
|
||||||
}
|
}
|
||||||
|
|
@ -102,9 +99,9 @@ class RangeController extends Controller
|
||||||
*
|
*
|
||||||
* @param \App\Http\Requests\Bo\Ranges\UpdateRangeRequest $request
|
* @param \App\Http\Requests\Bo\Ranges\UpdateRangeRequest $request
|
||||||
* @param \App\Models\Range $range
|
* @param \App\Models\Range $range
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\RedirectResponse
|
||||||
*/
|
*/
|
||||||
public function update(UpdateRangeRequest $request, Range $range)
|
public function update(UpdateRangeRequest $request, Range $range): \Illuminate\Http\RedirectResponse
|
||||||
{
|
{
|
||||||
return DB::transaction(function () use ($request, $range) {
|
return DB::transaction(function () use ($request, $range) {
|
||||||
$range->fill($request->validated());
|
$range->fill($request->validated());
|
||||||
|
|
@ -113,7 +110,7 @@ class RangeController extends Controller
|
||||||
->route('bo.ranges.edit', $range)
|
->route('bo.ranges.edit', $range)
|
||||||
->with('success', trans(
|
->with('success', trans(
|
||||||
'crud.messages.has_been_updated',
|
'crud.messages.has_been_updated',
|
||||||
['model' => Str::singular(trans('models.classes.ranges'))]
|
['model' => trans('models.classes.range')]
|
||||||
));
|
));
|
||||||
} //end if
|
} //end if
|
||||||
return back();
|
return back();
|
||||||
|
|
@ -124,23 +121,23 @@ class RangeController extends Controller
|
||||||
* Remove the specified resource from storage.
|
* Remove the specified resource from storage.
|
||||||
*
|
*
|
||||||
* @param \App\Models\Range $range
|
* @param \App\Models\Range $range
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\RedirectResponse
|
||||||
*/
|
*/
|
||||||
public function destroy(Range $range)
|
public function destroy(Range $range): \Illuminate\Http\RedirectResponse
|
||||||
{
|
{
|
||||||
if ($range->deleteOrFail()) {
|
if ($range->deleteOrFail()) {
|
||||||
return redirect()
|
return redirect()
|
||||||
->route('bo.ranges.index')
|
->route('bo.ranges.index')
|
||||||
->with('success', trans(
|
->with('success', trans(
|
||||||
'crud.messages.has_been_deleted',
|
'crud.messages.has_been_deleted',
|
||||||
['model' => Str::singular(trans('models.classes.ranges'))]
|
['model' => trans('models.classes.range')]
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
return redirect()
|
return redirect()
|
||||||
->back()
|
->back()
|
||||||
->with('error', trans(
|
->with('error', trans(
|
||||||
':crud.messages.cannot_be_deleted',
|
':crud.messages.cannot_be_deleted',
|
||||||
['model' => Str::singular(trans('models.classes.ranges'))]
|
['model' => trans('models.classes.range')]
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,24 +9,21 @@ use App\Models\Range;
|
||||||
use App\Models\Recipe;
|
use App\Models\Recipe;
|
||||||
use App\Traits\Controllers\UpdateModelStatus;
|
use App\Traits\Controllers\UpdateModelStatus;
|
||||||
use App\Traits\Controllers\ChangesModelOrder;
|
use App\Traits\Controllers\ChangesModelOrder;
|
||||||
use App\Traits\Requests\HasPicture;
|
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Str;
|
|
||||||
|
|
||||||
class RecipeController extends Controller
|
class RecipeController extends Controller
|
||||||
{
|
{
|
||||||
use ChangesModelOrder;
|
use ChangesModelOrder;
|
||||||
use HasPicture;
|
|
||||||
use UpdateModelStatus;
|
use UpdateModelStatus;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display a listing of the resource.
|
* Display a listing of the resource.
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Http\Request $request
|
* @param \Illuminate\Http\Request $request
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Contracts\View\View
|
||||||
*/
|
*/
|
||||||
public function index(Request $request)
|
public function index(Request $request): \Illuminate\Contracts\View\View
|
||||||
{
|
{
|
||||||
/** @var \Illuminate\Database\Eloquent\Builder $recipe */
|
/** @var \Illuminate\Database\Eloquent\Builder $recipe */
|
||||||
$recipe = Recipe::query();
|
$recipe = Recipe::query();
|
||||||
|
|
@ -51,9 +48,9 @@ class RecipeController extends Controller
|
||||||
/**
|
/**
|
||||||
* Show the form for creating a new resource.
|
* Show the form for creating a new resource.
|
||||||
*
|
*
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Contracts\View\View
|
||||||
*/
|
*/
|
||||||
public function create()
|
public function create(): \Illuminate\Contracts\View\View
|
||||||
{
|
{
|
||||||
$rangeModels = Range::orderBy('order', 'ASC')->get();
|
$rangeModels = Range::orderBy('order', 'ASC')->get();
|
||||||
|
|
||||||
|
|
@ -64,13 +61,13 @@ class RecipeController extends Controller
|
||||||
* Store a newly created resource in storage.
|
* Store a newly created resource in storage.
|
||||||
*
|
*
|
||||||
* @param \App\Http\Requests\Bo\Recipes\StoreRecipeRequest $request
|
* @param \App\Http\Requests\Bo\Recipes\StoreRecipeRequest $request
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\RedirectResponse
|
||||||
*/
|
*/
|
||||||
public function store(StoreRecipeRequest $request)
|
public function store(StoreRecipeRequest $request): \Illuminate\Http\RedirectResponse
|
||||||
{
|
{
|
||||||
return DB::transaction(function () use ($request) {
|
return DB::transaction(function () use ($request) {
|
||||||
$recipe = new Recipe();
|
$recipe = new Recipe();
|
||||||
$tmpIngredients = \collect($request->validated()['ingredients'])->sortKeys();
|
$tmpIngredients = \collect($request->validated()['ingredients'])->sortKeys()->toArray();
|
||||||
$recipe->fill($request->validated());
|
$recipe->fill($request->validated());
|
||||||
$recipe->ingredients = $tmpIngredients;
|
$recipe->ingredients = $tmpIngredients;
|
||||||
|
|
||||||
|
|
@ -79,14 +76,14 @@ class RecipeController extends Controller
|
||||||
->route('bo.recipes.edit', $recipe)
|
->route('bo.recipes.edit', $recipe)
|
||||||
->with('success', trans(
|
->with('success', trans(
|
||||||
'crud.messages.has_been_created',
|
'crud.messages.has_been_created',
|
||||||
['model' => Str::singular(trans('models.classes.recipes'))]
|
['model' => trans('models.classes.recipe')]
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
return redirect()
|
return redirect()
|
||||||
->back()
|
->back()
|
||||||
->with('error', trans(
|
->with('error', trans(
|
||||||
'crud.messages.cannot_be_created',
|
'crud.messages.cannot_be_created',
|
||||||
['model' => Str::singular(trans('models.classes.recipes'))]
|
['model' => trans('models.classes.recipe')]
|
||||||
));
|
));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -95,9 +92,9 @@ class RecipeController extends Controller
|
||||||
* Show the form for editing the specified resource.
|
* Show the form for editing the specified resource.
|
||||||
*
|
*
|
||||||
* @param \App\Models\Recipe $recipe
|
* @param \App\Models\Recipe $recipe
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Contracts\View\View
|
||||||
*/
|
*/
|
||||||
public function edit(Recipe $recipe)
|
public function edit(Recipe $recipe): \Illuminate\Contracts\View\View
|
||||||
{
|
{
|
||||||
$rangeModels = Range::orderBy('order', 'ASC')->get();
|
$rangeModels = Range::orderBy('order', 'ASC')->get();
|
||||||
|
|
||||||
|
|
@ -112,12 +109,12 @@ class RecipeController extends Controller
|
||||||
*
|
*
|
||||||
* @param \App\Http\Requests\Bo\Recipes\UpdateRecipeRequest $request
|
* @param \App\Http\Requests\Bo\Recipes\UpdateRecipeRequest $request
|
||||||
* @param \App\Models\Recipe $recipe
|
* @param \App\Models\Recipe $recipe
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\RedirectResponse
|
||||||
*/
|
*/
|
||||||
public function update(UpdateRecipeRequest $request, Recipe $recipe)
|
public function update(UpdateRecipeRequest $request, Recipe $recipe): \Illuminate\Http\RedirectResponse
|
||||||
{
|
{
|
||||||
return DB::transaction(function () use ($request, $recipe) {
|
return DB::transaction(function () use ($request, $recipe) {
|
||||||
$tmpIngredients = \collect($request->validated()['ingredients'])->sortKeys();
|
$tmpIngredients = \collect($request->validated()['ingredients'])->sortKeys()->toArray();
|
||||||
$recipe->fill($request->validated());
|
$recipe->fill($request->validated());
|
||||||
$recipe->ingredients = $tmpIngredients;
|
$recipe->ingredients = $tmpIngredients;
|
||||||
|
|
||||||
|
|
@ -126,14 +123,14 @@ class RecipeController extends Controller
|
||||||
->route('bo.recipes.edit', $recipe)
|
->route('bo.recipes.edit', $recipe)
|
||||||
->with('success', trans(
|
->with('success', trans(
|
||||||
'crud.messages.has_been_updated',
|
'crud.messages.has_been_updated',
|
||||||
['model' => Str::singular(trans('models.classes.recipes'))]
|
['model' => trans('models.classes.recipe')]
|
||||||
));
|
));
|
||||||
} //end if
|
} //end if
|
||||||
return redirect()
|
return redirect()
|
||||||
->back()
|
->back()
|
||||||
->with('error', trans(
|
->with('error', trans(
|
||||||
'crud.messages.cannot_be_updated',
|
'crud.messages.cannot_be_updated',
|
||||||
['model' => Str::singular(trans('models.classes.recipes'))]
|
['model' => trans('models.classes.recipe')]
|
||||||
));
|
));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -142,9 +139,9 @@ class RecipeController extends Controller
|
||||||
* Remove the specified resource from storage.
|
* Remove the specified resource from storage.
|
||||||
*
|
*
|
||||||
* @param \App\Models\Recipe $recipe
|
* @param \App\Models\Recipe $recipe
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\RedirectResponse
|
||||||
*/
|
*/
|
||||||
public function destroy(Recipe $recipe)
|
public function destroy(Recipe $recipe): \Illuminate\Http\RedirectResponse
|
||||||
{
|
{
|
||||||
return DB::transaction(function () use ($recipe) {
|
return DB::transaction(function () use ($recipe) {
|
||||||
$recipe->products()->detach();
|
$recipe->products()->detach();
|
||||||
|
|
@ -153,14 +150,14 @@ class RecipeController extends Controller
|
||||||
->route('bo.recipes.index')
|
->route('bo.recipes.index')
|
||||||
->with('success', trans(
|
->with('success', trans(
|
||||||
'crud.messages.has_been_deleted',
|
'crud.messages.has_been_deleted',
|
||||||
['model' => Str::singular(trans('models.classes.recipes'))]
|
['model' => trans('models.classes.recipe')]
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
return redirect()
|
return redirect()
|
||||||
->back()
|
->back()
|
||||||
->with('error', trans(
|
->with('error', trans(
|
||||||
':crud.messages.cannot_be_deleted',
|
':crud.messages.cannot_be_deleted',
|
||||||
['model' => Str::singular(trans('models.classes.recipes'))]
|
['model' => trans('models.classes.recipe')]
|
||||||
));
|
));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,6 @@ use App\Traits\Controllers\UpdateModelStatus;
|
||||||
use App\Traits\Controllers\ChangesModelOrder;
|
use App\Traits\Controllers\ChangesModelOrder;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Str;
|
|
||||||
|
|
||||||
class SliderController extends Controller
|
class SliderController extends Controller
|
||||||
{
|
{
|
||||||
|
|
@ -21,9 +20,9 @@ class SliderController extends Controller
|
||||||
* Display a listing of the resource.
|
* Display a listing of the resource.
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Http\Request $request
|
* @param \Illuminate\Http\Request $request
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Contracts\View\View
|
||||||
*/
|
*/
|
||||||
public function index(Request $request)
|
public function index(Request $request): \Illuminate\Contracts\View\View
|
||||||
{
|
{
|
||||||
/** @var \Illuminate\Database\Eloquent\Builder $sliders */
|
/** @var \Illuminate\Database\Eloquent\Builder $sliders */
|
||||||
$sliders = Slider::query();
|
$sliders = Slider::query();
|
||||||
|
|
@ -49,9 +48,9 @@ class SliderController extends Controller
|
||||||
/**
|
/**
|
||||||
* Show the form for creating a new resource.
|
* Show the form for creating a new resource.
|
||||||
*
|
*
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Contracts\View\View
|
||||||
*/
|
*/
|
||||||
public function create()
|
public function create(): \Illuminate\Contracts\View\View
|
||||||
{
|
{
|
||||||
return view('bo.pages.sliders.create');
|
return view('bo.pages.sliders.create');
|
||||||
}
|
}
|
||||||
|
|
@ -60,9 +59,9 @@ class SliderController extends Controller
|
||||||
* Store a newly created resource in storage.
|
* Store a newly created resource in storage.
|
||||||
*
|
*
|
||||||
* @param \App\Http\Requests\Bo\Sliders\StoreSliderRequest $request
|
* @param \App\Http\Requests\Bo\Sliders\StoreSliderRequest $request
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\RedirectResponse
|
||||||
*/
|
*/
|
||||||
public function store(StoreSliderRequest $request)
|
public function store(StoreSliderRequest $request): \Illuminate\Http\RedirectResponse
|
||||||
{
|
{
|
||||||
return DB::transaction(function () use ($request) {
|
return DB::transaction(function () use ($request) {
|
||||||
$slider = new Slider();
|
$slider = new Slider();
|
||||||
|
|
@ -73,14 +72,14 @@ class SliderController extends Controller
|
||||||
->route('bo.sliders.edit', $slider)
|
->route('bo.sliders.edit', $slider)
|
||||||
->with('success', trans(
|
->with('success', trans(
|
||||||
'crud.messages.has_been_created',
|
'crud.messages.has_been_created',
|
||||||
['model' => Str::singular(trans('models.classes.sliders'))]
|
['model' => trans('models.classes.slider')]
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
return redirect()
|
return redirect()
|
||||||
->back()
|
->back()
|
||||||
->with('error', trans(
|
->with('error', trans(
|
||||||
'crud.messages.cannot_be_created',
|
'crud.messages.cannot_be_created',
|
||||||
['model' => Str::singular(trans('models.classes.sliders'))]
|
['model' => trans('models.classes.slider')]
|
||||||
));
|
));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -89,9 +88,9 @@ class SliderController extends Controller
|
||||||
* Show the form for editing the specified resource.
|
* Show the form for editing the specified resource.
|
||||||
*
|
*
|
||||||
* @param \App\Models\Slider $slider
|
* @param \App\Models\Slider $slider
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Contracts\View\View
|
||||||
*/
|
*/
|
||||||
public function edit(Slider $slider)
|
public function edit(Slider $slider): \Illuminate\Contracts\View\View
|
||||||
{
|
{
|
||||||
return view('bo.pages.sliders.edit', [
|
return view('bo.pages.sliders.edit', [
|
||||||
'sliderModel' => $slider
|
'sliderModel' => $slider
|
||||||
|
|
@ -103,9 +102,9 @@ class SliderController extends Controller
|
||||||
*
|
*
|
||||||
* @param \App\Http\Requests\Bo\Sliders\UpdateSliderRequest $request
|
* @param \App\Http\Requests\Bo\Sliders\UpdateSliderRequest $request
|
||||||
* @param \App\Models\Slider $slider
|
* @param \App\Models\Slider $slider
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\RedirectResponse
|
||||||
*/
|
*/
|
||||||
public function update(UpdateSliderRequest $request, Slider $slider)
|
public function update(UpdateSliderRequest $request, Slider $slider): \Illuminate\Http\RedirectResponse
|
||||||
{
|
{
|
||||||
return DB::transaction(function () use ($request, $slider) {
|
return DB::transaction(function () use ($request, $slider) {
|
||||||
$slider->fill($request->validated());
|
$slider->fill($request->validated());
|
||||||
|
|
@ -115,14 +114,14 @@ class SliderController extends Controller
|
||||||
->route('bo.sliders.edit', $slider)
|
->route('bo.sliders.edit', $slider)
|
||||||
->with('success', trans(
|
->with('success', trans(
|
||||||
'crud.messages.has_been_updated',
|
'crud.messages.has_been_updated',
|
||||||
['model' => Str::singular(trans('models.classes.sliders'))]
|
['model' => trans('models.classes.slider')]
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
return redirect()
|
return redirect()
|
||||||
->back()
|
->back()
|
||||||
->with('error', trans(
|
->with('error', trans(
|
||||||
'crud.messages.cannot_be_updated',
|
'crud.messages.cannot_be_updated',
|
||||||
['model' => Str::singular(trans('models.classes.sliders'))]
|
['model' => trans('models.classes.slider')]
|
||||||
));
|
));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -131,23 +130,23 @@ class SliderController extends Controller
|
||||||
* Remove the specified resource from storage.
|
* Remove the specified resource from storage.
|
||||||
*
|
*
|
||||||
* @param \App\Models\Slider $slider
|
* @param \App\Models\Slider $slider
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\RedirectResponse
|
||||||
*/
|
*/
|
||||||
public function destroy(Slider $slider)
|
public function destroy(Slider $slider): \Illuminate\Http\RedirectResponse
|
||||||
{
|
{
|
||||||
if ($slider->deleteOrFail()) {
|
if ($slider->deleteOrFail()) {
|
||||||
return redirect()
|
return redirect()
|
||||||
->route('bo.sliders.index')
|
->route('bo.sliders.index')
|
||||||
->with('success', trans(
|
->with('success', trans(
|
||||||
'crud.messages.has_been_deleted',
|
'crud.messages.has_been_deleted',
|
||||||
['model' => Str::singular(trans('models.classes.sliders'))]
|
['model' => trans('models.classes.slider')]
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
return redirect()
|
return redirect()
|
||||||
->back()
|
->back()
|
||||||
->with('error', trans(
|
->with('error', trans(
|
||||||
':crud.messages.cannot_be_deleted',
|
':crud.messages.cannot_be_deleted',
|
||||||
['model' => Str::singular(trans('models.classes.sliders'))]
|
['model' => trans('models.classes.slider')]
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
90
app/Http/Controllers/Bo/StaticPageController.php
Normal file
90
app/Http/Controllers/Bo/StaticPageController.php
Normal file
|
|
@ -0,0 +1,90 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Bo;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Http\Requests\Bo\StaticPages\UpdateStaticPageRequest;
|
||||||
|
use App\Models\StaticPage;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class StaticPageController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Create the controller instance.
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->authorizeResource(StaticPage::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 $query */
|
||||||
|
$query = StaticPage::query();
|
||||||
|
|
||||||
|
/** @var string $search Search field */
|
||||||
|
$search = $request->search;
|
||||||
|
if ($search) {
|
||||||
|
$this->searchQuery(
|
||||||
|
$query,
|
||||||
|
$search,
|
||||||
|
null,
|
||||||
|
'title',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
$searchFields = \implode(', ', [
|
||||||
|
trans('validation.attributes.title'),
|
||||||
|
]);
|
||||||
|
|
||||||
|
/** Sort columns with a query */
|
||||||
|
$this->sortQuery($query);
|
||||||
|
|
||||||
|
/** Custom pagination */
|
||||||
|
$staticPageModels = $query->paginate(10);
|
||||||
|
|
||||||
|
return view('bo.pages.static_pages.index', compact('staticPageModels', 'search', 'searchFields'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show the form for editing the specified resource.
|
||||||
|
*
|
||||||
|
* @param \App\Models\StaticPage $static_page
|
||||||
|
* @return \Illuminate\Contracts\View\View
|
||||||
|
*/
|
||||||
|
public function edit(StaticPage $static_page): \Illuminate\Contracts\View\View
|
||||||
|
{
|
||||||
|
return view('bo.pages.static_pages.edit', ['staticPageModel' => $static_page]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the specified resource in storage.
|
||||||
|
*
|
||||||
|
* @param \App\Http\Requests\Bo\StaticPages\UpdateStaticPageRequest $request
|
||||||
|
* @param \App\Models\StaticPage $static_page
|
||||||
|
* @return \Illuminate\Http\RedirectResponse
|
||||||
|
*/
|
||||||
|
public function update(UpdateStaticPageRequest $request, StaticPage $static_page): \Illuminate\Http\RedirectResponse
|
||||||
|
{
|
||||||
|
return DB::transaction(function () use ($request, $static_page) {
|
||||||
|
$static_page->fill($request->validated());
|
||||||
|
|
||||||
|
if ($static_page->saveOrFail()) {
|
||||||
|
return redirect()->route('bo.static_pages.edit', $static_page)
|
||||||
|
->with('success', __('crud.messages.has_been_updated', [
|
||||||
|
'model' => trans('models.classes.static_page')
|
||||||
|
]));
|
||||||
|
}
|
||||||
|
return redirect()->route('bo.static_pages.edit', $static_page)
|
||||||
|
->with('error', __('crud.messages.cannot_be_updated', [
|
||||||
|
'model' => trans('models.classes.static_page')
|
||||||
|
]));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -10,24 +10,21 @@ use App\Models\StoreType;
|
||||||
use App\Models\StoreRegion;
|
use App\Models\StoreRegion;
|
||||||
use App\Traits\Controllers\UpdateModelStatus;
|
use App\Traits\Controllers\UpdateModelStatus;
|
||||||
use App\Traits\Controllers\ChangesModelOrder;
|
use App\Traits\Controllers\ChangesModelOrder;
|
||||||
use App\Traits\Requests\HasPicture;
|
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Str;
|
|
||||||
|
|
||||||
class StoreController extends Controller
|
class StoreController extends Controller
|
||||||
{
|
{
|
||||||
use ChangesModelOrder;
|
use ChangesModelOrder;
|
||||||
use HasPicture;
|
|
||||||
use UpdateModelStatus;
|
use UpdateModelStatus;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display a listing of the resource.
|
* Display a listing of the resource.
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Http\Request $request
|
* @param \Illuminate\Http\Request $request
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Contracts\View\View
|
||||||
*/
|
*/
|
||||||
public function index(Request $request)
|
public function index(Request $request): \Illuminate\Contracts\View\View
|
||||||
{
|
{
|
||||||
/** @var \Illuminate\Database\Eloquent\Builder $store */
|
/** @var \Illuminate\Database\Eloquent\Builder $store */
|
||||||
$store = Store::query();
|
$store = Store::query();
|
||||||
|
|
@ -52,9 +49,9 @@ class StoreController extends Controller
|
||||||
/**
|
/**
|
||||||
* Show the form for creating a new resource.
|
* Show the form for creating a new resource.
|
||||||
*
|
*
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Contracts\View\View
|
||||||
*/
|
*/
|
||||||
public function create()
|
public function create(): \Illuminate\Contracts\View\View
|
||||||
{
|
{
|
||||||
$typeModels = StoreType::orderBy('name', 'ASC')->get();
|
$typeModels = StoreType::orderBy('name', 'ASC')->get();
|
||||||
$regionModels = StoreRegion::orderBy('name', 'ASC')->get();
|
$regionModels = StoreRegion::orderBy('name', 'ASC')->get();
|
||||||
|
|
@ -66,9 +63,9 @@ class StoreController extends Controller
|
||||||
* Store a newly created resource in storage.
|
* Store a newly created resource in storage.
|
||||||
*
|
*
|
||||||
* @param \App\Http\Requests\Bo\Stores\StoreStoreRequest $request
|
* @param \App\Http\Requests\Bo\Stores\StoreStoreRequest $request
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\RedirectResponse
|
||||||
*/
|
*/
|
||||||
public function store(StoreStoreRequest $request)
|
public function store(StoreStoreRequest $request): \Illuminate\Http\RedirectResponse
|
||||||
{
|
{
|
||||||
return DB::transaction(function () use ($request) {
|
return DB::transaction(function () use ($request) {
|
||||||
$store = new Store();
|
$store = new Store();
|
||||||
|
|
@ -79,14 +76,14 @@ class StoreController extends Controller
|
||||||
->route('bo.stores.edit', $store)
|
->route('bo.stores.edit', $store)
|
||||||
->with('success', trans(
|
->with('success', trans(
|
||||||
'crud.messages.has_been_created',
|
'crud.messages.has_been_created',
|
||||||
['model' => Str::singular(trans('models.classes.stores'))]
|
['model' => trans('models.classes.store')]
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
return redirect()
|
return redirect()
|
||||||
->back()
|
->back()
|
||||||
->with('error', trans(
|
->with('error', trans(
|
||||||
'crud.messages.cannot_be_created',
|
'crud.messages.cannot_be_created',
|
||||||
['model' => Str::singular(trans('models.classes.stores'))]
|
['model' => trans('models.classes.store')]
|
||||||
));
|
));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -95,9 +92,9 @@ class StoreController extends Controller
|
||||||
* Display a listing of the resource.
|
* Display a listing of the resource.
|
||||||
*
|
*
|
||||||
* @param \App\Models\Store $store
|
* @param \App\Models\Store $store
|
||||||
* @return \Illuminate\Contracts\View\View|\Illuminate\Contracts\View\Factory
|
* @return \Illuminate\Contracts\View\View
|
||||||
*/
|
*/
|
||||||
public function edit(Store $store)
|
public function edit(Store $store): \Illuminate\Contracts\View\View
|
||||||
{
|
{
|
||||||
$typeModels = StoreType::orderBy('name', 'ASC')->get();
|
$typeModels = StoreType::orderBy('name', 'ASC')->get();
|
||||||
$regionModels = StoreRegion::orderBy('name', 'ASC')->get();
|
$regionModels = StoreRegion::orderBy('name', 'ASC')->get();
|
||||||
|
|
@ -113,9 +110,9 @@ class StoreController extends Controller
|
||||||
*
|
*
|
||||||
* @param \App\Http\Requests\Bo\Stores\UpdateStoreRequest $request
|
* @param \App\Http\Requests\Bo\Stores\UpdateStoreRequest $request
|
||||||
* @param \App\Models\Store $store
|
* @param \App\Models\Store $store
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\RedirectResponse
|
||||||
*/
|
*/
|
||||||
public function update(UpdateStoreRequest $request, Store $store)
|
public function update(UpdateStoreRequest $request, Store $store): \Illuminate\Http\RedirectResponse
|
||||||
{
|
{
|
||||||
return DB::transaction(function () use ($request, $store) {
|
return DB::transaction(function () use ($request, $store) {
|
||||||
$store->fill($request->validated());
|
$store->fill($request->validated());
|
||||||
|
|
@ -124,14 +121,14 @@ class StoreController extends Controller
|
||||||
->route('bo.stores.edit', $store)
|
->route('bo.stores.edit', $store)
|
||||||
->with('success', trans(
|
->with('success', trans(
|
||||||
'crud.messages.has_been_updated',
|
'crud.messages.has_been_updated',
|
||||||
['model' => Str::singular(trans('models.classes.stores'))]
|
['model' => trans('models.classes.store')]
|
||||||
));
|
));
|
||||||
} //end if
|
} //end if
|
||||||
return redirect()
|
return redirect()
|
||||||
->back()
|
->back()
|
||||||
->with('error', trans(
|
->with('error', trans(
|
||||||
'crud.messages.cannot_be_updated',
|
'crud.messages.cannot_be_updated',
|
||||||
['model' => Str::singular(trans('models.classes.stores'))]
|
['model' => trans('models.classes.store')]
|
||||||
));
|
));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -140,23 +137,23 @@ class StoreController extends Controller
|
||||||
* Remove the specified resource from storage.
|
* Remove the specified resource from storage.
|
||||||
*
|
*
|
||||||
* @param \App\Models\Store $store
|
* @param \App\Models\Store $store
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\RedirectResponse
|
||||||
*/
|
*/
|
||||||
public function destroy(Store $store)
|
public function destroy(Store $store): \Illuminate\Http\RedirectResponse
|
||||||
{
|
{
|
||||||
if ($store->deleteOrFail()) {
|
if ($store->deleteOrFail()) {
|
||||||
return redirect()
|
return redirect()
|
||||||
->route('bo.stores.index')
|
->route('bo.stores.index')
|
||||||
->with('success', trans(
|
->with('success', trans(
|
||||||
'crud.messages.has_been_deleted',
|
'crud.messages.has_been_deleted',
|
||||||
['model' => Str::singular(trans('models.classes.stores'))]
|
['model' => trans('models.classes.store')]
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
return redirect()
|
return redirect()
|
||||||
->back()
|
->back()
|
||||||
->with('error', trans(
|
->with('error', trans(
|
||||||
':crud.messages.cannot_be_deleted',
|
':crud.messages.cannot_be_deleted',
|
||||||
['model' => Str::singular(trans('models.classes.stores'))]
|
['model' => trans('models.classes.store')]
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,24 +8,21 @@ use App\Http\Requests\Bo\StoreGroups\UpdateStoreGroupRequest;
|
||||||
use App\Models\StoreGroup;
|
use App\Models\StoreGroup;
|
||||||
use App\Traits\Controllers\UpdateModelStatus;
|
use App\Traits\Controllers\UpdateModelStatus;
|
||||||
use App\Traits\Controllers\ChangesModelOrder;
|
use App\Traits\Controllers\ChangesModelOrder;
|
||||||
use App\Traits\Requests\HasPicture;
|
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Str;
|
|
||||||
|
|
||||||
class StoreGroupController extends Controller
|
class StoreGroupController extends Controller
|
||||||
{
|
{
|
||||||
use ChangesModelOrder;
|
use ChangesModelOrder;
|
||||||
use HasPicture;
|
|
||||||
use UpdateModelStatus;
|
use UpdateModelStatus;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display a listing of the resource.
|
* Display a listing of the resource.
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Http\Request $request
|
* @param \Illuminate\Http\Request $request
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Contracts\View\View
|
||||||
*/
|
*/
|
||||||
public function index(Request $request)
|
public function index(Request $request): \Illuminate\Contracts\View\View
|
||||||
{
|
{
|
||||||
/** @var \Illuminate\Database\Eloquent\Builder $storeGroup */
|
/** @var \Illuminate\Database\Eloquent\Builder $storeGroup */
|
||||||
$storeGroup = StoreGroup::query();
|
$storeGroup = StoreGroup::query();
|
||||||
|
|
@ -50,9 +47,9 @@ class StoreGroupController extends Controller
|
||||||
/**
|
/**
|
||||||
* Show the form for creating a new resource.
|
* Show the form for creating a new resource.
|
||||||
*
|
*
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Contracts\View\View
|
||||||
*/
|
*/
|
||||||
public function create()
|
public function create(): \Illuminate\Contracts\View\View
|
||||||
{
|
{
|
||||||
return view('bo.pages.storegroups.create');
|
return view('bo.pages.storegroups.create');
|
||||||
}
|
}
|
||||||
|
|
@ -61,9 +58,9 @@ class StoreGroupController extends Controller
|
||||||
* Store a newly created resource in storage.
|
* Store a newly created resource in storage.
|
||||||
*
|
*
|
||||||
* @param \App\Http\Requests\Bo\StoreGroups\StoreStoreGroupRequest $request
|
* @param \App\Http\Requests\Bo\StoreGroups\StoreStoreGroupRequest $request
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\RedirectResponse
|
||||||
*/
|
*/
|
||||||
public function store(StoreStoreGroupRequest $request)
|
public function store(StoreStoreGroupRequest $request): \Illuminate\Http\RedirectResponse
|
||||||
{
|
{
|
||||||
return DB::transaction(function () use ($request) {
|
return DB::transaction(function () use ($request) {
|
||||||
$storeGroup = new StoreGroup();
|
$storeGroup = new StoreGroup();
|
||||||
|
|
@ -74,14 +71,14 @@ class StoreGroupController extends Controller
|
||||||
->route('bo.storegroups.edit', $storeGroup)
|
->route('bo.storegroups.edit', $storeGroup)
|
||||||
->with('success', trans(
|
->with('success', trans(
|
||||||
'crud.messages.has_been_created',
|
'crud.messages.has_been_created',
|
||||||
['model' => Str::singular(trans('models.classes.storegroups'))]
|
['model' => trans('models.classes.storegroup')]
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
return redirect()
|
return redirect()
|
||||||
->back()
|
->back()
|
||||||
->with('error', trans(
|
->with('error', trans(
|
||||||
'crud.messages.cannot_be_created',
|
'crud.messages.cannot_be_created',
|
||||||
['model' => Str::singular(trans('models.classes.storegroups'))]
|
['model' => trans('models.classes.storegroup')]
|
||||||
));
|
));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -90,9 +87,9 @@ class StoreGroupController extends Controller
|
||||||
* Display a listing of the resource.
|
* Display a listing of the resource.
|
||||||
*
|
*
|
||||||
* @param \App\Models\StoreGroup $storegroup
|
* @param \App\Models\StoreGroup $storegroup
|
||||||
* @return \Illuminate\Contracts\View\View|\Illuminate\Contracts\View\Factory
|
* @return \Illuminate\Contracts\View\View
|
||||||
*/
|
*/
|
||||||
public function edit(StoreGroup $storegroup)
|
public function edit(StoreGroup $storegroup): \Illuminate\Contracts\View\View
|
||||||
{
|
{
|
||||||
return view('bo.pages.storegroups.edit', ['storegroupModel' => $storegroup]);
|
return view('bo.pages.storegroups.edit', ['storegroupModel' => $storegroup]);
|
||||||
}
|
}
|
||||||
|
|
@ -102,9 +99,9 @@ class StoreGroupController extends Controller
|
||||||
*
|
*
|
||||||
* @param \App\Http\Requests\Bo\StoreGroups\UpdateStoreGroupRequest $request
|
* @param \App\Http\Requests\Bo\StoreGroups\UpdateStoreGroupRequest $request
|
||||||
* @param \App\Models\StoreGroup $storegroup
|
* @param \App\Models\StoreGroup $storegroup
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\RedirectResponse
|
||||||
*/
|
*/
|
||||||
public function update(UpdateStoreGroupRequest $request, StoreGroup $storegroup)
|
public function update(UpdateStoreGroupRequest $request, StoreGroup $storegroup): \Illuminate\Http\RedirectResponse
|
||||||
{
|
{
|
||||||
return DB::transaction(function () use ($request, $storegroup) {
|
return DB::transaction(function () use ($request, $storegroup) {
|
||||||
$storegroup->fill($request->validated());
|
$storegroup->fill($request->validated());
|
||||||
|
|
@ -113,14 +110,14 @@ class StoreGroupController extends Controller
|
||||||
->route('bo.storegroups.edit', $storegroup)
|
->route('bo.storegroups.edit', $storegroup)
|
||||||
->with('success', trans(
|
->with('success', trans(
|
||||||
'crud.messages.has_been_updated',
|
'crud.messages.has_been_updated',
|
||||||
['model' => Str::singular(trans('models.classes.storegroups'))]
|
['model' => trans('models.classes.storegroup')]
|
||||||
));
|
));
|
||||||
} //end if
|
} //end if
|
||||||
return redirect()
|
return redirect()
|
||||||
->back()
|
->back()
|
||||||
->with('error', trans(
|
->with('error', trans(
|
||||||
'crud.messages.cannot_be_updated',
|
'crud.messages.cannot_be_updated',
|
||||||
['model' => Str::singular(trans('models.classes.storegroups'))]
|
['model' => trans('models.classes.storegroup')]
|
||||||
));
|
));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -129,9 +126,9 @@ class StoreGroupController extends Controller
|
||||||
* Remove the specified resource from storage.
|
* Remove the specified resource from storage.
|
||||||
*
|
*
|
||||||
* @param \App\Models\StoreGroup $storegroup
|
* @param \App\Models\StoreGroup $storegroup
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\RedirectResponse
|
||||||
*/
|
*/
|
||||||
public function destroy(StoreGroup $storegroup)
|
public function destroy(StoreGroup $storegroup): \Illuminate\Http\RedirectResponse
|
||||||
{
|
{
|
||||||
foreach ($storegroup->storeRegions as $region) {
|
foreach ($storegroup->storeRegions as $region) {
|
||||||
foreach ($region->stores as $store) {
|
foreach ($region->stores as $store) {
|
||||||
|
|
@ -145,14 +142,14 @@ class StoreGroupController extends Controller
|
||||||
->route('bo.storegroups.index')
|
->route('bo.storegroups.index')
|
||||||
->with('success', trans(
|
->with('success', trans(
|
||||||
'crud.messages.has_been_deleted',
|
'crud.messages.has_been_deleted',
|
||||||
['model' => Str::singular(trans('models.classes.storegroups'))]
|
['model' => trans('models.classes.storegroup')]
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
return redirect()
|
return redirect()
|
||||||
->back()
|
->back()
|
||||||
->with('error', trans(
|
->with('error', trans(
|
||||||
':crud.messages.cannot_be_deleted',
|
':crud.messages.cannot_be_deleted',
|
||||||
['model' => Str::singular(trans('models.classes.storegroups'))]
|
['model' => trans('models.classes.storegroup')]
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,24 +9,21 @@ use App\Models\StoreRegion;
|
||||||
use App\Models\StoreGroup;
|
use App\Models\StoreGroup;
|
||||||
use App\Traits\Controllers\UpdateModelStatus;
|
use App\Traits\Controllers\UpdateModelStatus;
|
||||||
use App\Traits\Controllers\ChangesModelOrder;
|
use App\Traits\Controllers\ChangesModelOrder;
|
||||||
use App\Traits\Requests\HasPicture;
|
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Str;
|
|
||||||
|
|
||||||
class StoreRegionController extends Controller
|
class StoreRegionController extends Controller
|
||||||
{
|
{
|
||||||
use ChangesModelOrder;
|
use ChangesModelOrder;
|
||||||
use HasPicture;
|
|
||||||
use UpdateModelStatus;
|
use UpdateModelStatus;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display a listing of the resource.
|
* Display a listing of the resource.
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Http\Request $request
|
* @param \Illuminate\Http\Request $request
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Contracts\View\View
|
||||||
*/
|
*/
|
||||||
public function index(Request $request)
|
public function index(Request $request): \Illuminate\Contracts\View\View
|
||||||
{
|
{
|
||||||
/** @var \Illuminate\Database\Eloquent\Builder $storeregion */
|
/** @var \Illuminate\Database\Eloquent\Builder $storeregion */
|
||||||
$storeregion = StoreRegion::query();
|
$storeregion = StoreRegion::query();
|
||||||
|
|
@ -51,9 +48,9 @@ class StoreRegionController extends Controller
|
||||||
/**
|
/**
|
||||||
* Show the form for creating a new resource.
|
* Show the form for creating a new resource.
|
||||||
*
|
*
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Contracts\View\View
|
||||||
*/
|
*/
|
||||||
public function create()
|
public function create(): \Illuminate\Contracts\View\View
|
||||||
{
|
{
|
||||||
$storegroupModels = StoreGroup::orderBy('order', 'ASC')->get();
|
$storegroupModels = StoreGroup::orderBy('order', 'ASC')->get();
|
||||||
|
|
||||||
|
|
@ -64,9 +61,9 @@ class StoreRegionController extends Controller
|
||||||
* Store a newly created resource in storage.
|
* Store a newly created resource in storage.
|
||||||
*
|
*
|
||||||
* @param \App\Http\Requests\Bo\StoreRegions\StoreStoreRegionRequest $request
|
* @param \App\Http\Requests\Bo\StoreRegions\StoreStoreRegionRequest $request
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\RedirectResponse
|
||||||
*/
|
*/
|
||||||
public function store(StoreStoreRegionRequest $request)
|
public function store(StoreStoreRegionRequest $request): \Illuminate\Http\RedirectResponse
|
||||||
{
|
{
|
||||||
return DB::transaction(function () use ($request) {
|
return DB::transaction(function () use ($request) {
|
||||||
$storeregion = new StoreRegion();
|
$storeregion = new StoreRegion();
|
||||||
|
|
@ -77,14 +74,14 @@ class StoreRegionController extends Controller
|
||||||
->route('bo.storeregions.edit', $storeregion)
|
->route('bo.storeregions.edit', $storeregion)
|
||||||
->with('success', trans(
|
->with('success', trans(
|
||||||
'crud.messages.has_been_created',
|
'crud.messages.has_been_created',
|
||||||
['model' => Str::singular(trans('models.classes.storeregions'))]
|
['model' => trans('models.classes.storeregion')]
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
return redirect()
|
return redirect()
|
||||||
->back()
|
->back()
|
||||||
->with('error', trans(
|
->with('error', trans(
|
||||||
'crud.messages.cannot_be_created',
|
'crud.messages.cannot_be_created',
|
||||||
['model' => Str::singular(trans('models.classes.storeregions'))]
|
['model' => trans('models.classes.storeregion')]
|
||||||
));
|
));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -93,9 +90,9 @@ class StoreRegionController extends Controller
|
||||||
* Show the form for editing the specified resource.
|
* Show the form for editing the specified resource.
|
||||||
*
|
*
|
||||||
* @param \App\Models\StoreRegion $storeregion
|
* @param \App\Models\StoreRegion $storeregion
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Contracts\View\View
|
||||||
*/
|
*/
|
||||||
public function edit(StoreRegion $storeregion)
|
public function edit(StoreRegion $storeregion): \Illuminate\Contracts\View\View
|
||||||
{
|
{
|
||||||
$storegroupModels = StoreGroup::orderBy('order', 'ASC')->get();
|
$storegroupModels = StoreGroup::orderBy('order', 'ASC')->get();
|
||||||
|
|
||||||
|
|
@ -110,10 +107,12 @@ class StoreRegionController extends Controller
|
||||||
*
|
*
|
||||||
* @param \App\Http\Requests\Bo\StoreRegions\UpdateStoreRegionRequest $request
|
* @param \App\Http\Requests\Bo\StoreRegions\UpdateStoreRegionRequest $request
|
||||||
* @param \App\Models\StoreRegion $storeregion
|
* @param \App\Models\StoreRegion $storeregion
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\RedirectResponse
|
||||||
*/
|
*/
|
||||||
public function update(UpdateStoreRegionRequest $request, StoreRegion $storeregion)
|
public function update(
|
||||||
{
|
UpdateStoreRegionRequest $request,
|
||||||
|
StoreRegion $storeregion
|
||||||
|
): \Illuminate\Http\RedirectResponse {
|
||||||
return DB::transaction(function () use ($request, $storeregion) {
|
return DB::transaction(function () use ($request, $storeregion) {
|
||||||
$storeregion->fill($request->validated());
|
$storeregion->fill($request->validated());
|
||||||
|
|
||||||
|
|
@ -122,14 +121,14 @@ class StoreRegionController extends Controller
|
||||||
->route('bo.storeregions.edit', $storeregion)
|
->route('bo.storeregions.edit', $storeregion)
|
||||||
->with('success', trans(
|
->with('success', trans(
|
||||||
'crud.messages.has_been_updated',
|
'crud.messages.has_been_updated',
|
||||||
['model' => Str::singular(trans('models.classes.storeregions'))]
|
['model' => trans('models.classes.storeregion')]
|
||||||
));
|
));
|
||||||
} //end if
|
} //end if
|
||||||
return redirect()
|
return redirect()
|
||||||
->back()
|
->back()
|
||||||
->with('error', trans(
|
->with('error', trans(
|
||||||
'crud.messages.cannot_be_updated',
|
'crud.messages.cannot_be_updated',
|
||||||
['model' => Str::singular(trans('models.classes.storeregions'))]
|
['model' => trans('models.classes.storeregion')]
|
||||||
));
|
));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -138,9 +137,9 @@ class StoreRegionController extends Controller
|
||||||
* Remove the specified resource from storage.
|
* Remove the specified resource from storage.
|
||||||
*
|
*
|
||||||
* @param \App\Models\StoreRegion $storeregion
|
* @param \App\Models\StoreRegion $storeregion
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\RedirectResponse
|
||||||
*/
|
*/
|
||||||
public function destroy(StoreRegion $storeregion)
|
public function destroy(StoreRegion $storeregion): \Illuminate\Http\RedirectResponse
|
||||||
{
|
{
|
||||||
foreach ($storeregion->stores as $store) {
|
foreach ($storeregion->stores as $store) {
|
||||||
$store->deleteOrFail();
|
$store->deleteOrFail();
|
||||||
|
|
@ -150,14 +149,14 @@ class StoreRegionController extends Controller
|
||||||
->route('bo.storeregions.index')
|
->route('bo.storeregions.index')
|
||||||
->with('success', trans(
|
->with('success', trans(
|
||||||
'crud.messages.has_been_deleted',
|
'crud.messages.has_been_deleted',
|
||||||
['model' => Str::singular(trans('models.classes.storeregions'))]
|
['model' => trans('models.classes.storeregion')]
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
return redirect()
|
return redirect()
|
||||||
->back()
|
->back()
|
||||||
->with('error', trans(
|
->with('error', trans(
|
||||||
':crud.messages.cannot_be_deleted',
|
':crud.messages.cannot_be_deleted',
|
||||||
['model' => Str::singular(trans('models.classes.storeregions'))]
|
['model' => trans('models.classes.storeregion')]
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,24 +8,21 @@ use App\Http\Requests\Bo\StoreTypes\UpdateStoreTypeRequest;
|
||||||
use App\Models\StoreType;
|
use App\Models\StoreType;
|
||||||
use App\Traits\Controllers\UpdateModelStatus;
|
use App\Traits\Controllers\UpdateModelStatus;
|
||||||
use App\Traits\Controllers\ChangesModelOrder;
|
use App\Traits\Controllers\ChangesModelOrder;
|
||||||
use App\Traits\Requests\HasPicture;
|
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Str;
|
|
||||||
|
|
||||||
class StoreTypeController extends Controller
|
class StoreTypeController extends Controller
|
||||||
{
|
{
|
||||||
use ChangesModelOrder;
|
use ChangesModelOrder;
|
||||||
use HasPicture;
|
|
||||||
use UpdateModelStatus;
|
use UpdateModelStatus;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display a listing of the resource.
|
* Display a listing of the resource.
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Http\Request $request
|
* @param \Illuminate\Http\Request $request
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Contracts\View\View
|
||||||
*/
|
*/
|
||||||
public function index(Request $request)
|
public function index(Request $request): \Illuminate\Contracts\View\View
|
||||||
{
|
{
|
||||||
/** @var \Illuminate\Database\Eloquent\Builder $storetype */
|
/** @var \Illuminate\Database\Eloquent\Builder $storetype */
|
||||||
$storetype = StoreType::query();
|
$storetype = StoreType::query();
|
||||||
|
|
@ -50,9 +47,9 @@ class StoreTypeController extends Controller
|
||||||
/**
|
/**
|
||||||
* Show the form for creating a new resource.
|
* Show the form for creating a new resource.
|
||||||
*
|
*
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Contracts\View\View
|
||||||
*/
|
*/
|
||||||
public function create()
|
public function create(): \Illuminate\Contracts\View\View
|
||||||
{
|
{
|
||||||
return view('bo.pages.storetypes.create');
|
return view('bo.pages.storetypes.create');
|
||||||
}
|
}
|
||||||
|
|
@ -61,9 +58,9 @@ class StoreTypeController extends Controller
|
||||||
* Store a newly created resource in storage.
|
* Store a newly created resource in storage.
|
||||||
*
|
*
|
||||||
* @param \App\Http\Requests\Bo\StoreTypes\StoreStoreTypeRequest $request
|
* @param \App\Http\Requests\Bo\StoreTypes\StoreStoreTypeRequest $request
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\RedirectResponse
|
||||||
*/
|
*/
|
||||||
public function store(StoreStoreTypeRequest $request)
|
public function store(StoreStoreTypeRequest $request): \Illuminate\Http\RedirectResponse
|
||||||
{
|
{
|
||||||
return DB::transaction(function () use ($request) {
|
return DB::transaction(function () use ($request) {
|
||||||
$storetype = new StoreType();
|
$storetype = new StoreType();
|
||||||
|
|
@ -74,14 +71,14 @@ class StoreTypeController extends Controller
|
||||||
->route('bo.storetypes.edit', $storetype)
|
->route('bo.storetypes.edit', $storetype)
|
||||||
->with('success', trans(
|
->with('success', trans(
|
||||||
'crud.messages.has_been_created',
|
'crud.messages.has_been_created',
|
||||||
['model' => Str::singular(trans('models.classes.storetypes'))]
|
['model' => trans('models.classes.storetype')]
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
return redirect()
|
return redirect()
|
||||||
->back()
|
->back()
|
||||||
->with('error', trans(
|
->with('error', trans(
|
||||||
'crud.messages.cannot_be_created',
|
'crud.messages.cannot_be_created',
|
||||||
['model' => Str::singular(trans('models.classes.storetypes'))]
|
['model' => trans('models.classes.storetype')]
|
||||||
));
|
));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -90,9 +87,9 @@ class StoreTypeController extends Controller
|
||||||
* Show the form for editing the specified resource.
|
* Show the form for editing the specified resource.
|
||||||
*
|
*
|
||||||
* @param \App\Models\StoreType $storetype
|
* @param \App\Models\StoreType $storetype
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Contracts\View\View
|
||||||
*/
|
*/
|
||||||
public function edit(StoreType $storetype)
|
public function edit(StoreType $storetype): \Illuminate\Contracts\View\View
|
||||||
{
|
{
|
||||||
return view('bo.pages.storetypes.edit', [
|
return view('bo.pages.storetypes.edit', [
|
||||||
'storetypeModel' => $storetype,
|
'storetypeModel' => $storetype,
|
||||||
|
|
@ -104,9 +101,9 @@ class StoreTypeController extends Controller
|
||||||
*
|
*
|
||||||
* @param \App\Http\Requests\Bo\StoreTypes\UpdateStoreTypeRequest $request
|
* @param \App\Http\Requests\Bo\StoreTypes\UpdateStoreTypeRequest $request
|
||||||
* @param \App\Models\StoreType $storetype
|
* @param \App\Models\StoreType $storetype
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\RedirectResponse
|
||||||
*/
|
*/
|
||||||
public function update(UpdateStoreTypeRequest $request, StoreType $storetype)
|
public function update(UpdateStoreTypeRequest $request, StoreType $storetype): \Illuminate\Http\RedirectResponse
|
||||||
{
|
{
|
||||||
return DB::transaction(function () use ($request, $storetype) {
|
return DB::transaction(function () use ($request, $storetype) {
|
||||||
$storetype->fill($request->validated());
|
$storetype->fill($request->validated());
|
||||||
|
|
@ -116,14 +113,14 @@ class StoreTypeController extends Controller
|
||||||
->route('bo.storetypes.edit', $storetype)
|
->route('bo.storetypes.edit', $storetype)
|
||||||
->with('success', trans(
|
->with('success', trans(
|
||||||
'crud.messages.has_been_updated',
|
'crud.messages.has_been_updated',
|
||||||
['model' => Str::singular(trans('models.classes.storetypes'))]
|
['model' => trans('models.classes.storetype')]
|
||||||
));
|
));
|
||||||
} //end if
|
} //end if
|
||||||
return redirect()
|
return redirect()
|
||||||
->back()
|
->back()
|
||||||
->with('error', trans(
|
->with('error', trans(
|
||||||
'crud.messages.cannot_be_updated',
|
'crud.messages.cannot_be_updated',
|
||||||
['model' => Str::singular(trans('models.classes.storetypes'))]
|
['model' => trans('models.classes.storetype')]
|
||||||
));
|
));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -132,9 +129,9 @@ class StoreTypeController extends Controller
|
||||||
* Remove the specified resource from storage.
|
* Remove the specified resource from storage.
|
||||||
*
|
*
|
||||||
* @param \App\Models\StoreType $storetype
|
* @param \App\Models\StoreType $storetype
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\RedirectResponse
|
||||||
*/
|
*/
|
||||||
public function destroy(StoreType $storetype)
|
public function destroy(StoreType $storetype): \Illuminate\Http\RedirectResponse
|
||||||
{
|
{
|
||||||
foreach ($storetype->stores as $store) {
|
foreach ($storetype->stores as $store) {
|
||||||
$store->deleteOrFail();
|
$store->deleteOrFail();
|
||||||
|
|
@ -144,14 +141,14 @@ class StoreTypeController extends Controller
|
||||||
->route('bo.storetypes.index')
|
->route('bo.storetypes.index')
|
||||||
->with('success', trans(
|
->with('success', trans(
|
||||||
'crud.messages.has_been_deleted',
|
'crud.messages.has_been_deleted',
|
||||||
['model' => Str::singular(trans('models.classes.storetypes'))]
|
['model' => trans('models.classes.storetype')]
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
return redirect()
|
return redirect()
|
||||||
->back()
|
->back()
|
||||||
->with('error', trans(
|
->with('error', trans(
|
||||||
':crud.messages.cannot_be_deleted',
|
':crud.messages.cannot_be_deleted',
|
||||||
['model' => Str::singular(trans('models.classes.storetypes'))]
|
['model' => trans('models.classes.storetype')]
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -109,10 +109,7 @@ class Controller extends BaseController
|
||||||
Session::remove("$rName.sort_way");
|
Session::remove("$rName.sort_way");
|
||||||
}
|
}
|
||||||
if (request()->sort_col and request()->sort_way and Schema::hasColumn($table, request()->sort_col)) {
|
if (request()->sort_col and request()->sort_way and Schema::hasColumn($table, request()->sort_col)) {
|
||||||
if (
|
if (!in_array(request()->input('sort_col'), $ignore)) {
|
||||||
!isset($ignore) or
|
|
||||||
(isset($ignore) and !in_array(request()->sort_col, $ignore))
|
|
||||||
) {
|
|
||||||
$query = $query->orderBy(\sprintf("$table.%s", request()->sort_col), request()->sort_way);
|
$query = $query->orderBy(\sprintf("$table.%s", request()->sort_col), request()->sort_way);
|
||||||
}
|
}
|
||||||
} elseif (Schema::hasColumn($table, 'order')) {
|
} elseif (Schema::hasColumn($table, 'order')) {
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,10 @@
|
||||||
|
|
||||||
namespace App\Http\Controllers\Fo;
|
namespace App\Http\Controllers\Fo;
|
||||||
|
|
||||||
|
use App\Enums\StaticPageType;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Models\Concept;
|
use App\Models\Concept;
|
||||||
|
use App\Models\StaticPage;
|
||||||
|
|
||||||
class ConceptController extends Controller
|
class ConceptController extends Controller
|
||||||
{
|
{
|
||||||
|
|
@ -13,8 +15,9 @@ class ConceptController extends Controller
|
||||||
* @param \App\Models\Concept $concept
|
* @param \App\Models\Concept $concept
|
||||||
* @return \Illuminate\Contracts\View\View
|
* @return \Illuminate\Contracts\View\View
|
||||||
*/
|
*/
|
||||||
public function show(Concept $concept)
|
public function show(Concept $concept): \Illuminate\Contracts\View\View
|
||||||
{
|
{
|
||||||
return view('fo.pages.concepts.concept', ['conceptModel' => $concept]);
|
$staticPageModel = StaticPage::query()->where('type', StaticPageType::concept)->firstOrFail();
|
||||||
|
return view('fo.pages.concepts.concept', ['staticPageModel' => $staticPageModel, 'conceptModel' => $concept]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,30 +2,33 @@
|
||||||
|
|
||||||
namespace App\Http\Controllers\Fo;
|
namespace App\Http\Controllers\Fo;
|
||||||
|
|
||||||
|
use App\Enums\StaticPageType;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Http\Requests\Fo\ContactRequest;
|
use App\Http\Requests\Fo\ContactRequest;
|
||||||
use App\Mail\ContactMessageReceived;
|
use App\Mail\ContactMessageReceived;
|
||||||
|
use App\Models\StaticPage;
|
||||||
use Illuminate\Support\Facades\Mail;
|
use Illuminate\Support\Facades\Mail;
|
||||||
|
|
||||||
class ContactController extends Controller
|
class ContactController extends Controller
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Show contact page
|
* Show contact page.
|
||||||
*
|
*
|
||||||
* @return \Illuminate\Contracts\View\View
|
* @return \Illuminate\Contracts\View\View
|
||||||
*/
|
*/
|
||||||
public function contactForm()
|
public function contactForm(): \Illuminate\Contracts\View\View
|
||||||
{
|
{
|
||||||
return view('fo.pages.contact');
|
$staticPageModel = StaticPage::query()->where('type', StaticPageType::contact)->firstOrFail();
|
||||||
|
return view('fo.pages.contact', \compact('staticPageModel'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Submit contact form
|
* Submit contact form.
|
||||||
*
|
*
|
||||||
* @param \App\Http\Requests\Fo\ContactRequest $request
|
* @param \App\Http\Requests\Fo\ContactRequest $request
|
||||||
* @return \Illuminate\Http\RedirectResponse
|
* @return \Illuminate\Http\RedirectResponse
|
||||||
*/
|
*/
|
||||||
public function sendContactForm(ContactRequest $request)
|
public function sendContactForm(ContactRequest $request): \Illuminate\Http\RedirectResponse
|
||||||
{
|
{
|
||||||
Mail::queue(new ContactMessageReceived(
|
Mail::queue(new ContactMessageReceived(
|
||||||
first_name: $request->first_name,
|
first_name: $request->first_name,
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ class GroupController extends Controller
|
||||||
* @param integer $id
|
* @param integer $id
|
||||||
* @return \App\Models\StoreGroup
|
* @return \App\Models\StoreGroup
|
||||||
*/
|
*/
|
||||||
public function show(int $id)
|
public function show(int $id): \App\Models\StoreGroup
|
||||||
{
|
{
|
||||||
return StoreGroup::query()->find($id);
|
return StoreGroup::query()->find($id);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,11 @@
|
||||||
|
|
||||||
namespace App\Http\Controllers\Fo;
|
namespace App\Http\Controllers\Fo;
|
||||||
|
|
||||||
|
use App\Enums\StaticPageType;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Models\Home;
|
use App\Models\Home;
|
||||||
use App\Models\Slider;
|
use App\Models\Slider;
|
||||||
|
use App\Models\StaticPage;
|
||||||
|
|
||||||
class HomeController extends Controller
|
class HomeController extends Controller
|
||||||
{
|
{
|
||||||
|
|
@ -13,10 +15,16 @@ class HomeController extends Controller
|
||||||
*
|
*
|
||||||
* @return \Illuminate\Contracts\View\View
|
* @return \Illuminate\Contracts\View\View
|
||||||
*/
|
*/
|
||||||
public function index()
|
public function index(): \Illuminate\Contracts\View\View
|
||||||
{
|
{
|
||||||
$home = Home::query()->firstOrFail();
|
$staticPageModel = StaticPage::query()->where('type', StaticPageType::home)->firstOrFail();
|
||||||
$sliders = Slider::query()->where('status', true)->orderBy('order')->get();
|
$currentLocale = app()->currentLocale();
|
||||||
return view('fo.pages.home', compact('home', 'sliders'));
|
$home = Home::query()->firstOrFail();
|
||||||
|
$sliders = Slider::query()
|
||||||
|
->where('status', true)
|
||||||
|
->orderBy('order')
|
||||||
|
->whereJsonContains('locales', $currentLocale)
|
||||||
|
->get();
|
||||||
|
return view('fo.pages.home', compact('staticPageModel', 'home', 'sliders'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
81
app/Http/Controllers/Fo/NewsController.php
Normal file
81
app/Http/Controllers/Fo/NewsController.php
Normal file
|
|
@ -0,0 +1,81 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Fo;
|
||||||
|
|
||||||
|
use App\Enums\StaticPageType;
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Models\News;
|
||||||
|
use App\Models\StaticPage;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\Cache;
|
||||||
|
|
||||||
|
class NewsController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* News index
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @return \Illuminate\Contracts\View\View|\Illuminate\Http\JsonResponse
|
||||||
|
*/
|
||||||
|
public function index(Request $request): \Illuminate\Contracts\View\View|\Illuminate\Http\JsonResponse
|
||||||
|
{
|
||||||
|
$staticPageModel = StaticPage::query()->where('type', StaticPageType::newsPlural)->firstOrFail();
|
||||||
|
if ($request->wantsJson()) {
|
||||||
|
$currentLocale = app()->currentLocale();
|
||||||
|
$newsList = News::query()
|
||||||
|
->where('status', true)
|
||||||
|
->whereJsonContains('locales', $currentLocale)
|
||||||
|
->orderBy('order')
|
||||||
|
->paginate();
|
||||||
|
return \response()->json(\collect($newsList->items())
|
||||||
|
->map(fn ($newsModel) => str($this->renderNews($newsModel))->toBase64()));
|
||||||
|
}
|
||||||
|
return view('fo.pages.news.index', compact('staticPageModel'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Product show
|
||||||
|
*
|
||||||
|
* @param \App\Models\News $publishedNews
|
||||||
|
* @return \Illuminate\Contracts\View\View
|
||||||
|
*/
|
||||||
|
public function show(News $publishedNews): \Illuminate\Contracts\View\View
|
||||||
|
{
|
||||||
|
$staticPageModel = StaticPage::query()->where('type', StaticPageType::newsPlural)->firstOrFail();
|
||||||
|
$currentLocale = app()->currentLocale();
|
||||||
|
$relatedNewsList = News::query()
|
||||||
|
->where('id', '!=', $publishedNews->id)
|
||||||
|
->where('status', true)
|
||||||
|
->whereJsonContains('locales', $currentLocale)
|
||||||
|
->orderBy('order', 'DESC')
|
||||||
|
->limit(2)->get();
|
||||||
|
return view('fo.pages.news.show', [
|
||||||
|
'staticPageModel' => $staticPageModel,
|
||||||
|
'newsModel' => $publishedNews,
|
||||||
|
'relatedNewsList' => $relatedNewsList
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render a news for JS usage (ajax)
|
||||||
|
*
|
||||||
|
* @param \App\Models\News $newsModel
|
||||||
|
* @return string Base64 rendered view.
|
||||||
|
*/
|
||||||
|
private function renderNews(News $newsModel): string
|
||||||
|
{
|
||||||
|
$locale = \app()->currentLocale();
|
||||||
|
$pictures = $newsModel->picture_list;
|
||||||
|
return Cache::remember(
|
||||||
|
"NewsRendered_{$locale}_{$newsModel->id}_{$newsModel->updated_at}",
|
||||||
|
60,
|
||||||
|
fn () => \view(
|
||||||
|
'fo.pages.news.bloc',
|
||||||
|
[
|
||||||
|
'newsModel' => $newsModel,
|
||||||
|
'pictures' => $pictures
|
||||||
|
]
|
||||||
|
)->render()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -2,36 +2,44 @@
|
||||||
|
|
||||||
namespace App\Http\Controllers\Fo;
|
namespace App\Http\Controllers\Fo;
|
||||||
|
|
||||||
|
use App\Enums\StaticPageType;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Models\Product;
|
use App\Models\Product;
|
||||||
use App\Models\Range;
|
use App\Models\Range;
|
||||||
|
use App\Models\StaticPage;
|
||||||
use Illuminate\Contracts\Database\Eloquent\Builder;
|
use Illuminate\Contracts\Database\Eloquent\Builder;
|
||||||
|
|
||||||
class ProductController extends Controller
|
class ProductController extends Controller
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Products index
|
* Products index.
|
||||||
*
|
*
|
||||||
* @return \Illuminate\Contracts\View\View
|
* @return \Illuminate\Contracts\View\View
|
||||||
*/
|
*/
|
||||||
public function index()
|
public function index(): \Illuminate\Contracts\View\View
|
||||||
{
|
{
|
||||||
$ranges = Range::query()->where('status', true)
|
$staticPageModel = StaticPage::query()->where('type', StaticPageType::products)->firstOrFail();
|
||||||
->whereHas('products', fn (Builder $q) => $q->where('status', true))
|
$rangeModels = Range::query()
|
||||||
->with('products', fn (Builder $q) => $q->where('status', true)->orderBy('order'))
|
->where('status', true)
|
||||||
|
->whereHas('products', fn(Builder $q) => $q->where('status', true))
|
||||||
|
->with('products', fn(Builder $q) => $q->where('status', true)->orderBy('order'))
|
||||||
->orderBy('order')
|
->orderBy('order')
|
||||||
->get();
|
->get();
|
||||||
return view('fo.pages.products.index', compact(['ranges']));
|
return view('fo.pages.products.index', compact('staticPageModel', 'rangeModels'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Product show
|
* Product show.
|
||||||
*
|
*
|
||||||
* @param \App\Models\Product $publishedProduct
|
* @param \App\Models\Product $publishedProduct
|
||||||
* @return \Illuminate\Contracts\View\View
|
* @return \Illuminate\Contracts\View\View
|
||||||
*/
|
*/
|
||||||
public function show(Product $publishedProduct)
|
public function show(Product $publishedProduct): \Illuminate\Contracts\View\View
|
||||||
{
|
{
|
||||||
return view('fo.pages.products.show', ['productModel' => $publishedProduct]);
|
$staticPageModel = StaticPage::query()->where('type', StaticPageType::product)->firstOrFail();
|
||||||
|
return view('fo.pages.products.show', [
|
||||||
|
'staticPageModel' => $staticPageModel,
|
||||||
|
'productModel' => $publishedProduct,
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,10 @@
|
||||||
|
|
||||||
namespace App\Http\Controllers\Fo;
|
namespace App\Http\Controllers\Fo;
|
||||||
|
|
||||||
|
use App\Enums\StaticPageType;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Models\Recipe;
|
use App\Models\Recipe;
|
||||||
|
use App\Models\StaticPage;
|
||||||
use Illuminate\Contracts\Database\Eloquent\Builder;
|
use Illuminate\Contracts\Database\Eloquent\Builder;
|
||||||
|
|
||||||
class RecipeController extends Controller
|
class RecipeController extends Controller
|
||||||
|
|
@ -13,13 +15,14 @@ class RecipeController extends Controller
|
||||||
*
|
*
|
||||||
* @return \Illuminate\Contracts\View\View
|
* @return \Illuminate\Contracts\View\View
|
||||||
*/
|
*/
|
||||||
public function index()
|
public function index(): \Illuminate\Contracts\View\View
|
||||||
{
|
{
|
||||||
$recipes = Recipe::query()->where('status', true)
|
$staticPageModel = StaticPage::query()->where('type', StaticPageType::recipes)->firstOrFail();
|
||||||
|
$recipeModels = Recipe::query()->where('status', true)
|
||||||
->whereHas('range', fn (Builder $q) => $q->where('status', true))
|
->whereHas('range', fn (Builder $q) => $q->where('status', true))
|
||||||
->orderBy('order')
|
->orderBy('order')
|
||||||
->get();
|
->get();
|
||||||
return view('fo.pages.recipes.index', compact('recipes'));
|
return view('fo.pages.recipes.index', compact('staticPageModel', 'recipeModels'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -28,8 +31,12 @@ class RecipeController extends Controller
|
||||||
* @param \App\Models\Recipe $publishedRecipe
|
* @param \App\Models\Recipe $publishedRecipe
|
||||||
* @return \Illuminate\Contracts\View\View
|
* @return \Illuminate\Contracts\View\View
|
||||||
*/
|
*/
|
||||||
public function show(Recipe $publishedRecipe)
|
public function show(Recipe $publishedRecipe): \Illuminate\Contracts\View\View
|
||||||
{
|
{
|
||||||
return view('fo.pages.recipes.show', ['recipeModel' => $publishedRecipe]);
|
$staticPageModel = StaticPage::query()->where('type', StaticPageType::recipe)->firstOrFail();
|
||||||
|
return view('fo.pages.recipes.show', [
|
||||||
|
'staticPageModel' => $staticPageModel,
|
||||||
|
'recipeModel' => $publishedRecipe,
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ class RegionController extends Controller
|
||||||
* @param integer $id
|
* @param integer $id
|
||||||
* @return \App\Models\StoreRegion;
|
* @return \App\Models\StoreRegion;
|
||||||
*/
|
*/
|
||||||
public function show(int $id)
|
public function show(int $id): \App\Models\StoreRegion
|
||||||
{
|
{
|
||||||
return StoreRegion::find($id);
|
return StoreRegion::find($id);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
34
app/Http/Controllers/Fo/StaticPageController.php
Normal file
34
app/Http/Controllers/Fo/StaticPageController.php
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Fo;
|
||||||
|
|
||||||
|
use App\Enums\StaticPageType;
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Models\StaticPage;
|
||||||
|
|
||||||
|
class StaticPageController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Legal show
|
||||||
|
*
|
||||||
|
* @param \App\Models\StaticPage $legalPage
|
||||||
|
* @return \Illuminate\Contracts\View\View
|
||||||
|
*/
|
||||||
|
public function legals(StaticPage $legalPage)
|
||||||
|
{
|
||||||
|
$legalPage = StaticPage::query()->where('type', StaticPageType::legals)->firstOrFail();
|
||||||
|
return view('fo.pages.legals', ['staticPageModel' => $legalPage]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Policies show
|
||||||
|
*
|
||||||
|
* @param \App\Models\StaticPage $policiesPage
|
||||||
|
* @return \Illuminate\Contracts\View\View
|
||||||
|
*/
|
||||||
|
public function policies(StaticPage $policiesPage)
|
||||||
|
{
|
||||||
|
$policiesPage = StaticPage::query()->where('type', StaticPageType::confidentiality)->firstOrFail();
|
||||||
|
return view('fo.pages.privacy', ['staticPageModel' => $policiesPage]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -2,21 +2,33 @@
|
||||||
|
|
||||||
namespace App\Http\Controllers\Fo;
|
namespace App\Http\Controllers\Fo;
|
||||||
|
|
||||||
|
use App\Enums\StaticPageType;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Http\Requests\Api\StoreFinderRequest;
|
use App\Http\Requests\Api\StoreFinderRequest;
|
||||||
use App\Http\Resources\StoreFinderResource;
|
use App\Http\Resources\StoreFinderResource;
|
||||||
|
use App\Models\StaticPage;
|
||||||
use App\Models\Store;
|
use App\Models\Store;
|
||||||
use Illuminate\Http\JsonResponse;
|
|
||||||
|
|
||||||
class StoreController extends Controller
|
class StoreController extends Controller
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Store by city
|
* Store page.
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Contracts\View\View
|
||||||
|
*/
|
||||||
|
public function index(): \Illuminate\Contracts\View\View
|
||||||
|
{
|
||||||
|
$staticPageModel = StaticPage::query()->where('type', StaticPageType::store)->firstOrFail();
|
||||||
|
return view('fo.pages.storefinder', compact('staticPageModel'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store by city.
|
||||||
*
|
*
|
||||||
* @param \App\Http\Requests\Api\StoreFinderRequest $request
|
* @param \App\Http\Requests\Api\StoreFinderRequest $request
|
||||||
* @return \Illuminate\Http\JsonResponse;
|
* @return \Illuminate\Http\JsonResponse
|
||||||
*/
|
*/
|
||||||
public function city(StoreFinderRequest $request): JsonResponse
|
public function city(StoreFinderRequest $request): \Illuminate\Http\JsonResponse
|
||||||
{
|
{
|
||||||
return \response()->json(new StoreFinderResource(Store::query()
|
return \response()->json(new StoreFinderResource(Store::query()
|
||||||
->where('city', 'LIKE', '%' . $request->input('city') . '%')
|
->where('city', 'LIKE', '%' . $request->input('city') . '%')
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,7 @@ class Kernel extends HttpKernel
|
||||||
\App\Http\Middleware\VerifyCsrfToken::class,
|
\App\Http\Middleware\VerifyCsrfToken::class,
|
||||||
\CodeZero\LocalizedRoutes\Middleware\SetLocale::class,
|
\CodeZero\LocalizedRoutes\Middleware\SetLocale::class,
|
||||||
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||||
|
\App\Http\Middleware\Lang::class,
|
||||||
\App\Http\Middleware\SecureHeaders::class,
|
\App\Http\Middleware\SecureHeaders::class,
|
||||||
],
|
],
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,6 @@ class Authenticate extends Middleware
|
||||||
}
|
}
|
||||||
return route('login');
|
return route('login');
|
||||||
}
|
}
|
||||||
abort(401);
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,9 @@ class Lang
|
||||||
app()->setLocale(session()->get('lang', config('app.locale')));
|
app()->setLocale(session()->get('lang', config('app.locale')));
|
||||||
return $next($request);
|
return $next($request);
|
||||||
}
|
}
|
||||||
|
if (Route::current()->getName() == null && count($request->all()) > 0) {
|
||||||
|
return redirect()->route('home', $request->all());
|
||||||
|
}
|
||||||
return $next($request);
|
return $next($request);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ class SecureHeaders
|
||||||
$jsDev = config('app.debug') ? "'unsafe-eval' 'unsafe-inline'" : "'nonce-{$nonce}' 'strict-dynamic'";
|
$jsDev = config('app.debug') ? "'unsafe-eval' 'unsafe-inline'" : "'nonce-{$nonce}' 'strict-dynamic'";
|
||||||
$scheme = config('app.env') === 'local' ? 'http' : 'https';
|
$scheme = config('app.env') === 'local' ? 'http' : 'https';
|
||||||
$reportUri = Route::has('cspReportUri') ?
|
$reportUri = Route::has('cspReportUri') ?
|
||||||
\sprintf(' report-uri %s ;', \parse_url(route('cspReportUri'), \PHP_URL_PATH)) : '';
|
\sprintf(' report-uri %s ;', \parse_url(route('cspReportUri'), \PHP_URL_PATH)) : '';
|
||||||
$this->removeUnwantedHeaders($this->unwantedHeaderList);
|
$this->removeUnwantedHeaders($this->unwantedHeaderList);
|
||||||
$response = $next($request);
|
$response = $next($request);
|
||||||
$response->headers->set('Referrer-Policy', 'no-referrer-when-downgrade');
|
$response->headers->set('Referrer-Policy', 'no-referrer-when-downgrade');
|
||||||
|
|
@ -84,7 +84,9 @@ class SecureHeaders
|
||||||
]) . ';',
|
]) . ';',
|
||||||
// ! If you dont use ckeditor use this
|
// ! If you dont use ckeditor use this
|
||||||
// "style-src 'self' 'nonce-$nonce';",
|
// "style-src 'self' 'nonce-$nonce';",
|
||||||
|
// phpcs:disable Generic.Commenting.Fixme.TaskFound
|
||||||
// FIXME: use Alpine CSP compliant.
|
// FIXME: use Alpine CSP compliant.
|
||||||
|
// phpcs:enable
|
||||||
// ! unsave Eval needed for Alpine JS de merde.
|
// ! unsave Eval needed for Alpine JS de merde.
|
||||||
// phpcs:ignore Generic.Files.LineLength.TooLong
|
// phpcs:ignore Generic.Files.LineLength.TooLong
|
||||||
"script-src 'self' 'unsafe-eval' {$jsDev} " . \implode(' ', [
|
"script-src 'self' 'unsafe-eval' {$jsDev} " . \implode(' ', [
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ class ChangeOrderRequest extends FormRequest
|
||||||
*
|
*
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function authorize()
|
public function authorize(): bool
|
||||||
{
|
{
|
||||||
return auth('backend')->check();
|
return auth('backend')->check();
|
||||||
}
|
}
|
||||||
|
|
@ -21,10 +21,10 @@ class ChangeOrderRequest extends FormRequest
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function prepareForValidation()
|
protected function prepareForValidation(): void
|
||||||
{
|
{
|
||||||
$this->merge([
|
$this->merge([
|
||||||
'direction' => $this->action === 'up' ? true : false
|
'direction' => $this->direction === 'up' ? true : false
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -33,10 +33,9 @@ class ChangeOrderRequest extends FormRequest
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function rules()
|
public function rules(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'action' => 'required|string|in:up,down',
|
|
||||||
'direction' => 'required|boolean',
|
'direction' => 'required|boolean',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ class StoreConceptRequest extends UpdateMiniCrudRequest
|
||||||
*
|
*
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function authorize()
|
public function authorize(): bool
|
||||||
{
|
{
|
||||||
return (auth('backend')->check() && Concept::count() < 9);
|
return (auth('backend')->check() && Concept::count() < 9);
|
||||||
}
|
}
|
||||||
|
|
@ -35,10 +35,10 @@ class StoreConceptRequest extends UpdateMiniCrudRequest
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function prepareForValidation()
|
protected function prepareForValidation(): void
|
||||||
{
|
{
|
||||||
$this->merge([
|
$this->merge([
|
||||||
'slug' => Str::slug(strip_tags($this->name))
|
'slug' => Str::slug(strip_tags($this->input('name')))
|
||||||
]);
|
]);
|
||||||
$this->mergePicture('picture');
|
$this->mergePicture('picture');
|
||||||
}
|
}
|
||||||
|
|
@ -48,25 +48,21 @@ class StoreConceptRequest extends UpdateMiniCrudRequest
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function rules()
|
public function rules(): array
|
||||||
{
|
{
|
||||||
$rules = [
|
$rules = [
|
||||||
'seo_title' => 'required|min:3|max:70',
|
'seo_title' => 'required|min:3|max:70',
|
||||||
'seo_description' => 'required|min:50|max:160',
|
'seo_description' => 'required|min:50|max:160',
|
||||||
|
'name' => 'required|min:3|max:70',
|
||||||
'name' => 'required|min:3|max:70',
|
'slug' => 'unique_translation:concepts',
|
||||||
'slug' => 'unique_translation:concepts',
|
'title' => 'required|min:3|max:70',
|
||||||
'title' => 'required|min:3|max:70',
|
'title_background_color' => ['required', new Enum(ColorsEnum::class)],
|
||||||
'title_background_color' => [
|
'subtitle' => 'required|min:3|max:70',
|
||||||
'required', new Enum(ColorsEnum::class)
|
'description' => 'required|string|min:15',
|
||||||
],
|
'data' => 'present|array',
|
||||||
'subtitle' => 'required|min:3|max:70',
|
'data.*' => 'required|array',
|
||||||
'description' => 'required|string|min:15',
|
'picture_alt' => 'required|min:3|max:255',
|
||||||
'data' => 'present|array',
|
'picture_title' => 'required|min:3|max:255',
|
||||||
'data.*' => 'required|array',
|
|
||||||
|
|
||||||
'picture_alt' => 'required|min:3|max:255',
|
|
||||||
'picture_title' => 'required|min:3|max:255',
|
|
||||||
];
|
];
|
||||||
return \array_merge(
|
return \array_merge(
|
||||||
parent::rules(),
|
parent::rules(),
|
||||||
|
|
@ -83,20 +79,18 @@ class StoreConceptRequest extends UpdateMiniCrudRequest
|
||||||
public function attributes()
|
public function attributes()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'seo_title' => trans('titre') . ' seo',
|
'seo_title' => trans('titre') . ' seo',
|
||||||
'seo_description' => trans('description') . ' seo',
|
'seo_description' => trans('description') . ' seo',
|
||||||
|
'name' => trans('name of the concept'),
|
||||||
'name' => trans('name of the concept'),
|
'slug' => trans('slug of the concept'),
|
||||||
'slug' => trans('slug of the concept'),
|
'title' => trans('title of the concept'),
|
||||||
'title' => trans('title of the concept'),
|
'subtitle' => trans('subtitle of the concept'),
|
||||||
'subtitle' => trans('subtitle of the concept'),
|
'description' => trans('description of the concept'),
|
||||||
'description' => trans('description of the concept'),
|
'data' => trans('values of the data'),
|
||||||
'data' => trans('values of the data'),
|
'data.*.value' => trans('value of the data'),
|
||||||
'data.*.value' => trans('value of the data'),
|
'picture' => trans('illustration'),
|
||||||
|
'picture_alt' => trans('alt attribute of the image'),
|
||||||
'picture' => trans('illustration'),
|
'picture_title' => trans('title attribute of the image'),
|
||||||
'picture_alt' => trans('alt attribute of the image'),
|
|
||||||
'picture_title' => trans('title attribute of the image'),
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ class UpdateConceptRequest extends StoreConceptRequest
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function rules()
|
public function rules(): array
|
||||||
{
|
{
|
||||||
$rules = [
|
$rules = [
|
||||||
'slug' => UniqueTranslationRule::for('concepts')->ignore($this->concept->id),
|
'slug' => UniqueTranslationRule::for('concepts')->ignore($this->concept->id),
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ class UpdateHomeRequest extends FormRequest
|
||||||
*
|
*
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function authorize()
|
public function authorize(): bool
|
||||||
{
|
{
|
||||||
return auth('backend')->check();
|
return auth('backend')->check();
|
||||||
}
|
}
|
||||||
|
|
@ -24,7 +24,7 @@ class UpdateHomeRequest extends FormRequest
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function prepareForValidation()
|
protected function prepareForValidation(): void
|
||||||
{
|
{
|
||||||
$this->mergePicture('part3_picture');
|
$this->mergePicture('part3_picture');
|
||||||
}
|
}
|
||||||
|
|
@ -34,28 +34,23 @@ class UpdateHomeRequest extends FormRequest
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function rules()
|
public function rules(): array
|
||||||
{
|
{
|
||||||
$rules = [
|
$rules = [
|
||||||
'seo_title' => 'required|min:3|max:70',
|
'part1_title' => 'required|min:3|max:70',
|
||||||
'seo_description' => 'required|min:50|max:160',
|
'part1_subtitle' => 'required|min:3|max:70',
|
||||||
|
'part1_text_1' => 'required|string|min:15',
|
||||||
'part1_title' => 'required|min:3|max:70',
|
'part1_text_2' => 'required|string|min:15',
|
||||||
'part1_subtitle' => 'required|min:3|max:70',
|
'part1_text_3' => 'required|string|min:15',
|
||||||
'part1_text_1' => 'required|string|min:15',
|
'part2_title' => 'required|min:3|max:70',
|
||||||
'part1_text_2' => 'required|string|min:15',
|
'part2_subtitle' => 'required|min:3|max:70',
|
||||||
'part1_text_3' => 'required|string|min:15',
|
'part2_text' => 'required|string|min:15',
|
||||||
|
'part2_list' => 'present|array',
|
||||||
'part2_title' => 'required|min:3|max:70',
|
'part2_list.*' => 'required|array',
|
||||||
'part2_subtitle' => 'required|min:3|max:70',
|
'part2_list.*.value' => 'required|string|min:3|max:255',
|
||||||
'part2_text' => 'required|string|min:15',
|
'part2_product1_id' => 'required|exists:products,id',
|
||||||
'part2_list' => 'present|array',
|
'part2_product2_id' => 'required|exists:products,id',
|
||||||
'part2_list.*' => 'required|array',
|
'part3_picture_alt' => 'required|min:3|max:255',
|
||||||
'part2_list.*.value' => 'required|string|min:3|max:255',
|
|
||||||
'part2_product1_id' => 'required|exists:products,id',
|
|
||||||
'part2_product2_id' => 'required|exists:products,id',
|
|
||||||
|
|
||||||
'part3_picture_alt' => 'required|min:3|max:255',
|
|
||||||
'part3_picture_title' => 'required|min:3|max:255',
|
'part3_picture_title' => 'required|min:3|max:255',
|
||||||
];
|
];
|
||||||
return \array_merge(
|
return \array_merge(
|
||||||
|
|
@ -69,28 +64,23 @@ class UpdateHomeRequest extends FormRequest
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function attributes()
|
public function attributes(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'seo_title' => trans('titre') . ' seo',
|
'part1_title' => trans('title part.1'),
|
||||||
'seo_description' => trans('description') . ' seo',
|
'part1_subtitle' => trans('subtitle part.1'),
|
||||||
|
'part1_text_1' => trans('text 1 part.1'),
|
||||||
'part1_title' => trans('title part.1'),
|
'part1_text_2' => trans('text 2 part.1'),
|
||||||
'part1_subtitle' => trans('subtitle part.1'),
|
'part1_text_3' => trans('text 3 part.1'),
|
||||||
'part1_text_1' => trans('text 1 part.1'),
|
'part2_title' => trans('title part.2'),
|
||||||
'part1_text_2' => trans('text 2 part.1'),
|
'part2_subtitle' => trans('subtitle part.2'),
|
||||||
'part1_text_3' => trans('text 3 part.1'),
|
'part2_text' => trans('text part.2'),
|
||||||
|
'part2_list' => trans('values of the list part.2'),
|
||||||
'part2_title' => trans('title part.2'),
|
'part2_list.*.value' => trans('value of the list part.2'),
|
||||||
'part2_subtitle' => trans('subtitle part.2'),
|
'part2_product1_id' => trans('value of the first product part.2'),
|
||||||
'part2_text' => trans('text part.2'),
|
'part2_product2_id' => trans('value of the second product part.2'),
|
||||||
'part2_list' => trans('values of the list part.2'),
|
'part3_picture' => trans('illustration'),
|
||||||
'part2_list.*.value' => trans('value of the list part.2'),
|
'part3_picture_alt' => trans('alt attribute of the image'),
|
||||||
'part2_product1_id' => trans('value of the first product part.2'),
|
|
||||||
'part2_product2_id' => trans('value of the second product part.2'),
|
|
||||||
|
|
||||||
'part3_picture' => trans('illustration'),
|
|
||||||
'part3_picture_alt' => trans('alt attribute of the image'),
|
|
||||||
'part3_picture_title' => trans('title attribute of the image'),
|
'part3_picture_title' => trans('title attribute of the image'),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
94
app/Http/Requests/Bo/News/StoreNewsRequest.php
Normal file
94
app/Http/Requests/Bo/News/StoreNewsRequest.php
Normal file
|
|
@ -0,0 +1,94 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests\Bo\News;
|
||||||
|
|
||||||
|
use App\Http\Requests\Bo\UpdateMiniCrudRequest;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
|
class StoreNewsRequest extends UpdateMiniCrudRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The model parameter name
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $modelName = 'news';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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(): void
|
||||||
|
{
|
||||||
|
$this->merge([
|
||||||
|
'slug' => Str::slug(strip_tags($this->input('name'))),
|
||||||
|
'status' => $this->boolean('status'),
|
||||||
|
'publish_at' => $this->date('publish_at'),
|
||||||
|
'unpublish_at' => $this->date('unpublish_at'),
|
||||||
|
'locales' => \collect($this->input('locales'))->filter()->unique()->all()
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
$rules = [
|
||||||
|
'seo_title' => 'required|min:3|max:70',
|
||||||
|
'seo_description' => 'required|min:50|max:160',
|
||||||
|
'slug' => 'unique_translation:news',
|
||||||
|
'title' => 'required|min:3|max:70',
|
||||||
|
'subtitle' => 'required|min:3|max:70',
|
||||||
|
'content' => 'required|string|min:15',
|
||||||
|
'locales' => 'required|array',
|
||||||
|
'locales.*' => [
|
||||||
|
'required',
|
||||||
|
\sprintf('in:%s', \implode(',', \config('app.locales')))
|
||||||
|
],
|
||||||
|
'data' => 'present|array',
|
||||||
|
'data.*' => 'required|array',
|
||||||
|
'data.bloc_1_display_picture.value' => 'required|accepted',
|
||||||
|
'status' => 'required|boolean',
|
||||||
|
'publish_at' => 'required|date',
|
||||||
|
'unpublish_at' => 'sometimes|nullable|date'
|
||||||
|
];
|
||||||
|
return \array_merge(
|
||||||
|
parent::rules(),
|
||||||
|
$rules
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get custom attributes for validator errors.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function attributes(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'seo_title' => trans('titre') . ' seo',
|
||||||
|
'seo_description' => trans('description') . ' seo',
|
||||||
|
'slug' => trans('slug of the news'),
|
||||||
|
'title' => trans('title of the news'),
|
||||||
|
'subtitle' => trans('subtitle of the news'),
|
||||||
|
'content' => trans('content of the news'),
|
||||||
|
'data' => trans('values of the data'),
|
||||||
|
'data.*.value' => trans('value of the data'),
|
||||||
|
'data.bloc_1_display_picture.value' => trans('visibility of the first picture')
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
25
app/Http/Requests/Bo/News/UpdateNewsRequest.php
Normal file
25
app/Http/Requests/Bo/News/UpdateNewsRequest.php
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests\Bo\News;
|
||||||
|
|
||||||
|
use App\Http\Requests\Bo\News\StoreNewsRequest;
|
||||||
|
use CodeZero\UniqueTranslation\UniqueTranslationRule;
|
||||||
|
|
||||||
|
class UpdateNewsRequest extends StoreNewsRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
$rules = [
|
||||||
|
'slug' => UniqueTranslationRule::for('news')->ignore($this->news->id),
|
||||||
|
];
|
||||||
|
return \array_merge(
|
||||||
|
parent::rules(),
|
||||||
|
$rules,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -15,7 +15,7 @@ class StoreProductRequest extends FormRequest
|
||||||
*
|
*
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function authorize()
|
public function authorize(): bool
|
||||||
{
|
{
|
||||||
return auth('backend')->check();
|
return auth('backend')->check();
|
||||||
}
|
}
|
||||||
|
|
@ -25,14 +25,14 @@ class StoreProductRequest extends FormRequest
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function prepareForValidation()
|
protected function prepareForValidation(): void
|
||||||
{
|
{
|
||||||
$this->merge([
|
$this->merge([
|
||||||
'slug' => Str::slug(strip_tags($this->label)),
|
'slug' => Str::slug(strip_tags($this->input('label'))),
|
||||||
'status' => $this->status ? true : false,
|
'status' => $this->boolean('status'),
|
||||||
'list' => $this->list ?? [],
|
'list' => $this->input('list') ?? [],
|
||||||
'nutritionnal_values' => $this->nutritionnal_values ?? [],
|
'nutritionnal_values' => $this->input('nutritionnal_values') ?? [],
|
||||||
'certifications' => \collect($this->certifications)->all(),
|
'certifications' => \collect($this->input('certifications'))->all(),
|
||||||
]);
|
]);
|
||||||
$this->mergePicture('picture');
|
$this->mergePicture('picture');
|
||||||
}
|
}
|
||||||
|
|
@ -42,44 +42,44 @@ class StoreProductRequest extends FormRequest
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function rules()
|
public function rules(): array
|
||||||
{
|
{
|
||||||
$rules = [
|
$rules = [
|
||||||
'seo_title' => 'required|min:3|max:70',
|
'seo_title' => 'required|min:3|max:70',
|
||||||
'seo_description' => 'required|min:50|max:160',
|
'seo_description' => 'required|min:50|max:160',
|
||||||
'label' => 'required|min:3|max:255',
|
'label' => 'required|min:3|max:255',
|
||||||
'slug' => 'unique_translation:products',
|
'slug' => 'unique_translation:products',
|
||||||
'description' => 'required|string|min:15',
|
'description' => 'required|string|min:15',
|
||||||
'marinade' => 'nullable|string|min:15',
|
'marinade' => 'nullable|string|min:15',
|
||||||
'picture_alt' => 'required|min:3|max:255',
|
'picture_alt' => 'required|min:3|max:255',
|
||||||
'picture_title' => 'required|min:3|max:255',
|
'picture_title' => 'required|min:3|max:255',
|
||||||
'picture_arrow_alt' => 'required_with:picture_arrow|min:3|max:255',
|
'picture_arrow_alt' => 'required_with:picture_arrow|min:3|max:255',
|
||||||
'picture_arrow_title' => 'required_with:picture_arrow|min:3|max:255',
|
'picture_arrow_title' => 'required_with:picture_arrow|min:3|max:255',
|
||||||
'certifications' => 'present|array',
|
'certifications' => 'present|array',
|
||||||
'certifications.*' => 'required|integer',
|
'certifications.*' => 'required|integer',
|
||||||
'list' => [
|
'list' => [
|
||||||
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
|
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed
|
||||||
'present', 'array', function ($attribute, array $value, $fail) {
|
'present', 'array', function ($attribute, array $value, $fail) {
|
||||||
if (1 > count($value)) {
|
if (1 > count($value)) {
|
||||||
$fail(\trans('You must fill in at least 2 lines in the list.'));
|
$fail(\trans('You must fill in at least 2 lines in the list.'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
'list.*' => 'required|array',
|
'list.*' => 'required|array',
|
||||||
'list.*.value' => 'nullable|string|min:3|max:255',
|
'list.*.value' => 'nullable|string|min:3|max:255',
|
||||||
'nutritionnal_values' => [
|
'nutritionnal_values' => [
|
||||||
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
|
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed
|
||||||
'present', 'array', function ($attribute, array $value, $fail) {
|
'present', 'array', function ($attribute, array $value, $fail) {
|
||||||
if (1 > count($value)) {
|
if (1 > count($value)) {
|
||||||
$fail(\trans('You must fill in at least 2 lines of nutritional values.'));
|
$fail(\trans('You must fill in at least 2 lines of nutritional values.'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
'nutritionnal_values.*' => 'required|array',
|
'nutritionnal_values.*' => 'required|array',
|
||||||
'nutritionnal_values.*.label' => 'nullable|string|min:3|max:255',
|
'nutritionnal_values.*.label' => 'nullable|string|min:3|max:255',
|
||||||
'nutritionnal_values.*.value' => 'nullable|string|min:1|max:255',
|
'nutritionnal_values.*.value' => 'nullable|string|min:1|max:255',
|
||||||
'range_id' => 'required|exists:ranges,id',
|
'range_id' => 'required|exists:ranges,id',
|
||||||
'status' => 'required|boolean'
|
'status' => 'required|boolean'
|
||||||
];
|
];
|
||||||
return \array_merge(
|
return \array_merge(
|
||||||
$rules,
|
$rules,
|
||||||
|
|
@ -96,25 +96,25 @@ class StoreProductRequest extends FormRequest
|
||||||
public function attributes(): array
|
public function attributes(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'seo_title' => trans('title') . ' seo',
|
'seo_title' => trans('title') . ' seo',
|
||||||
'seo_description' => trans('description') . ' seo',
|
'seo_description' => trans('description') . ' seo',
|
||||||
'label' => trans('label'),
|
'label' => trans('label'),
|
||||||
'slug' => trans('slug'),
|
'slug' => trans('slug'),
|
||||||
'description' => trans('description'),
|
'description' => trans('description'),
|
||||||
'marinade' => trans('marinade'),
|
'marinade' => trans('marinade'),
|
||||||
'picture_alt' => trans('picture_alt'),
|
'picture_alt' => trans('picture_alt'),
|
||||||
'picture_title' => trans('picture_title'),
|
'picture_title' => trans('picture_title'),
|
||||||
'picture_arrow' => trans('picture_arrow'),
|
'picture_arrow' => trans('picture_arrow'),
|
||||||
'picture_arrow_alt' => trans('picture_arrow_alt'),
|
'picture_arrow_alt' => trans('picture_arrow_alt'),
|
||||||
'picture_arrow_title' => trans('picture_arrow_title'),
|
'picture_arrow_title' => trans('picture_arrow_title'),
|
||||||
'certifications' => trans('certifications'),
|
'certifications' => trans('certifications'),
|
||||||
'certifications.*' => trans('value(s) of certifications'),
|
'certifications.*' => trans('value(s) of certifications'),
|
||||||
'list' => trans('list'),
|
'list' => trans('list'),
|
||||||
'nutritionnal_values' => trans('nutritionnal_values'),
|
'nutritionnal_values' => trans('nutritionnal_values'),
|
||||||
'nutritionnal_values.*.label' => trans('label(s) of nutritionnal_values'),
|
'nutritionnal_values.*.label' => trans('label(s) of nutritionnal_values'),
|
||||||
'nutritionnal_values.*.value' => trans('value(s) of nutritionnal_values'),
|
'nutritionnal_values.*.value' => trans('value(s) of nutritionnal_values'),
|
||||||
'range_id' => trans('range'),
|
'range_id' => trans('range'),
|
||||||
'status' => trans('publish'),
|
'status' => trans('publish'),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ class UpdateProductRequest extends StoreProductRequest
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function rules()
|
public function rules(): array
|
||||||
{
|
{
|
||||||
$rules = [
|
$rules = [
|
||||||
'seo_title' => 'required|min:3|max:70',
|
'seo_title' => 'required|min:3|max:70',
|
||||||
|
|
@ -27,7 +27,7 @@ class UpdateProductRequest extends StoreProductRequest
|
||||||
'certifications' => 'present|array',
|
'certifications' => 'present|array',
|
||||||
'certifications.*' => 'required|integer',
|
'certifications.*' => 'required|integer',
|
||||||
'list' => [
|
'list' => [
|
||||||
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
|
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed
|
||||||
'present', 'array', function ($attribute, array $value, $fail) {
|
'present', 'array', function ($attribute, array $value, $fail) {
|
||||||
if (1 > count($value)) {
|
if (1 > count($value)) {
|
||||||
$fail(\trans('You must fill in at least 2 lines in the list.'));
|
$fail(\trans('You must fill in at least 2 lines in the list.'));
|
||||||
|
|
@ -37,7 +37,7 @@ class UpdateProductRequest extends StoreProductRequest
|
||||||
'list.*' => 'required|array',
|
'list.*' => 'required|array',
|
||||||
'list.*.value' => 'nullable|string|min:3|max:255',
|
'list.*.value' => 'nullable|string|min:3|max:255',
|
||||||
'nutritionnal_values' => [
|
'nutritionnal_values' => [
|
||||||
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
|
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed
|
||||||
'present', 'array', function ($attribute, array $value, $fail) {
|
'present', 'array', function ($attribute, array $value, $fail) {
|
||||||
if (1 > count($value)) {
|
if (1 > count($value)) {
|
||||||
$fail(\trans('You must fill in at least 2 lines of nutritional values.'));
|
$fail(\trans('You must fill in at least 2 lines of nutritional values.'));
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ class StoreRangeRequest extends FormRequest
|
||||||
*
|
*
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function authorize()
|
public function authorize(): bool
|
||||||
{
|
{
|
||||||
return auth('backend')->check();
|
return auth('backend')->check();
|
||||||
}
|
}
|
||||||
|
|
@ -27,11 +27,11 @@ class StoreRangeRequest extends FormRequest
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function prepareForValidation()
|
protected function prepareForValidation(): void
|
||||||
{
|
{
|
||||||
$this->merge([
|
$this->merge([
|
||||||
'slug' => Str::slug(strip_tags($this->label)),
|
'slug' => Str::slug(strip_tags($this->input('label'))),
|
||||||
'status' => $this->status ? true : false,
|
'status' => $this->boolean('status'),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -40,15 +40,15 @@ class StoreRangeRequest extends FormRequest
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function rules()
|
public function rules(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'seo_title' => 'required|min:3|max:70',
|
'seo_title' => 'required|min:3|max:70',
|
||||||
'seo_description' => 'required|min:50|max:160',
|
'seo_description' => 'required|min:50|max:160',
|
||||||
'label' => 'required|min:3|max:255',
|
'label' => 'required|min:3|max:255',
|
||||||
'slug' => 'unique_translation:ranges',
|
'slug' => 'unique_translation:ranges',
|
||||||
'picto' => [new Enum(PictoEnum::class)],
|
'picto' => [new Enum(PictoEnum::class)],
|
||||||
'status' => 'required|boolean'
|
'status' => 'required|boolean'
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -60,12 +60,12 @@ class StoreRangeRequest extends FormRequest
|
||||||
public function attributes(): array
|
public function attributes(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'seo_title' => trans('title') . ' seo',
|
'seo_title' => trans('title') . ' seo',
|
||||||
'seo_description' => trans('description') . ' seo',
|
'seo_description' => trans('description') . ' seo',
|
||||||
'label' => trans('label'),
|
'label' => trans('label'),
|
||||||
'picto' => trans('picto'),
|
'picto' => trans('picto'),
|
||||||
'slug' => trans('slug'),
|
'slug' => trans('slug'),
|
||||||
'status' => trans('publish')
|
'status' => trans('publish')
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,7 @@
|
||||||
|
|
||||||
namespace App\Http\Requests\Bo\Ranges;
|
namespace App\Http\Requests\Bo\Ranges;
|
||||||
|
|
||||||
use App\Enums\Ranges\PictoEnum;
|
|
||||||
use CodeZero\UniqueTranslation\UniqueTranslationRule;
|
use CodeZero\UniqueTranslation\UniqueTranslationRule;
|
||||||
use Illuminate\Validation\Rules\Enum;
|
|
||||||
|
|
||||||
class UpdateRangeRequest extends StoreRangeRequest
|
class UpdateRangeRequest extends StoreRangeRequest
|
||||||
{
|
{
|
||||||
|
|
@ -13,15 +11,14 @@ class UpdateRangeRequest extends StoreRangeRequest
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function rules()
|
public function rules(): array
|
||||||
{
|
{
|
||||||
return [
|
$rules = [
|
||||||
'seo_title' => 'required|min:3|max:70',
|
|
||||||
'seo_description' => 'required|min:50|max:160',
|
|
||||||
'label' => 'required|min:3|max:255',
|
|
||||||
'slug' => UniqueTranslationRule::for('ranges')->ignore($this->range->id),
|
'slug' => UniqueTranslationRule::for('ranges')->ignore($this->range->id),
|
||||||
'picto' => [new Enum(PictoEnum::class)],
|
|
||||||
'status' => 'required|boolean'
|
|
||||||
];
|
];
|
||||||
|
return \array_merge(
|
||||||
|
parent::rules(),
|
||||||
|
$rules,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ class StoreRecipeRequest extends FormRequest
|
||||||
*
|
*
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function authorize()
|
public function authorize(): bool
|
||||||
{
|
{
|
||||||
return auth('backend')->check();
|
return auth('backend')->check();
|
||||||
}
|
}
|
||||||
|
|
@ -27,11 +27,11 @@ class StoreRecipeRequest extends FormRequest
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function prepareForValidation()
|
protected function prepareForValidation(): void
|
||||||
{
|
{
|
||||||
$this->merge([
|
$this->merge([
|
||||||
'slug' => Str::slug(strip_tags($this->name)),
|
'slug' => Str::slug(strip_tags($this->input('name'))),
|
||||||
'status' => $this->status ? true : false,
|
'status' => $this->boolean('status'),
|
||||||
]);
|
]);
|
||||||
$this->mergePicture('picture');
|
$this->mergePicture('picture');
|
||||||
$this->mergePicture('picture_thumbnail');
|
$this->mergePicture('picture_thumbnail');
|
||||||
|
|
@ -42,35 +42,35 @@ class StoreRecipeRequest extends FormRequest
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function rules()
|
public function rules(): array
|
||||||
{
|
{
|
||||||
$rules = [
|
$rules = [
|
||||||
'seo_title' => 'required|min:3|max:70',
|
'seo_title' => 'required|min:3|max:70',
|
||||||
'seo_description' => 'required|min:50|max:160',
|
'seo_description' => 'required|min:50|max:160',
|
||||||
'name' => 'required|min:3|max:255',
|
'name' => 'required|min:3|max:255',
|
||||||
'slug' => 'unique_translation:recipes',
|
'slug' => 'unique_translation:recipes',
|
||||||
'picture_alt' => 'required|min:3|max:255',
|
'picture_alt' => 'required|min:3|max:255',
|
||||||
'picture_title' => 'required|min:3|max:255',
|
'picture_title' => 'required|min:3|max:255',
|
||||||
'picture_thumbnail_alt' => 'required|min:3|max:255',
|
'picture_thumbnail_alt' => 'required|min:3|max:255',
|
||||||
'picture_thumbnail_title' => 'required|min:3|max:255',
|
'picture_thumbnail_title' => 'required|min:3|max:255',
|
||||||
'ingredients' => [
|
'ingredients' => [
|
||||||
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
|
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed
|
||||||
'present', 'array', function ($attribute, array $value, $fail) {
|
'present', 'array', function ($attribute, array $value, $fail) {
|
||||||
if (1 > count($value)) {
|
if (1 > count($value)) {
|
||||||
$fail(\trans('You must fill in at least 1 line of ingredients.'));
|
$fail(\trans('You must fill in at least 1 line of ingredients.'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
'ingredients.*' => 'nullable|array',
|
'ingredients.*' => 'nullable|array',
|
||||||
'ingredients.*.header' => 'nullable|string|min:2|max:255',
|
'ingredients.*.header' => 'nullable|string|min:2|max:255',
|
||||||
'ingredients.*.value' => 'string|min:2|max:255',
|
'ingredients.*.value' => 'string|min:2|max:255',
|
||||||
'teaser' => 'required|min:50|max:160',
|
'teaser' => 'required|min:50|max:160',
|
||||||
'steps' => 'required|string|min:15',
|
'steps' => 'required|string|min:15',
|
||||||
'difficulty' => [new Enum(DifficultyEnum::class)],
|
'difficulty' => [new Enum(DifficultyEnum::class)],
|
||||||
'duration' => 'required|string|min:1|max:150',
|
'duration' => 'required|numeric|between:1,1440',
|
||||||
'tips' => 'nullable|string|min:15',
|
'tips' => 'required|string|min:15',
|
||||||
'range_id' => 'required|exists:ranges,id',
|
'range_id' => 'required|exists:ranges,id',
|
||||||
'status' => 'required|boolean'
|
'status' => 'required|boolean'
|
||||||
];
|
];
|
||||||
return \array_merge(
|
return \array_merge(
|
||||||
$rules,
|
$rules,
|
||||||
|
|
@ -87,21 +87,21 @@ class StoreRecipeRequest extends FormRequest
|
||||||
public function attributes(): array
|
public function attributes(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'seo_title' => trans('title') . ' seo',
|
'seo_title' => trans('title') . ' seo',
|
||||||
'seo_description' => trans('description') . ' seo',
|
'seo_description' => trans('description') . ' seo',
|
||||||
'name' => trans('name'),
|
'name' => trans('name'),
|
||||||
'slug' => trans('slug'),
|
'slug' => trans('slug'),
|
||||||
'ingredients' => trans('ingredients'),
|
'ingredients' => trans('ingredients'),
|
||||||
'ingredients.*.header' => trans('header in the list of ingredients'),
|
'ingredients.*.header' => trans('header in the list of ingredients'),
|
||||||
'ingredients.*.label' => trans('value of ingredients'),
|
'ingredients.*.label' => trans('value of ingredients'),
|
||||||
'ingredients.*.value' => trans('value of ingredients'),
|
'ingredients.*.value' => trans('value of ingredients'),
|
||||||
'teaser' => trans('teaser'),
|
'teaser' => trans('teaser'),
|
||||||
'steps' => trans('steps'),
|
'steps' => trans('steps'),
|
||||||
'difficulty' => trans('difficulty'),
|
'difficulty' => trans('difficulty'),
|
||||||
'duration' => trans('duration'),
|
'duration' => trans('duration'),
|
||||||
'tips' => trans('tips'),
|
'tips' => trans('tips'),
|
||||||
'range_id' => trans('range'),
|
'range_id' => trans('range'),
|
||||||
'status' => trans('publish')
|
'status' => trans('publish')
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ class UpdateRecipeRequest extends StoreRecipeRequest
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function rules()
|
public function rules(): array
|
||||||
{
|
{
|
||||||
$rules = [
|
$rules = [
|
||||||
'slug' => UniqueTranslationRule::for('recipes')->ignore($this->recipe->id)
|
'slug' => UniqueTranslationRule::for('recipes')->ignore($this->recipe->id)
|
||||||
|
|
@ -19,8 +19,6 @@ class UpdateRecipeRequest extends StoreRecipeRequest
|
||||||
return \array_merge(
|
return \array_merge(
|
||||||
parent::rules(),
|
parent::rules(),
|
||||||
$rules,
|
$rules,
|
||||||
$this->pictureRules('picture', 1600, 900, 1600, 900, true),
|
|
||||||
$this->pictureRules('picture_thumbnail', 430, 242, 430, 242, true),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ class StoreSliderRequest extends FormRequest
|
||||||
*
|
*
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function authorize()
|
public function authorize(): bool
|
||||||
{
|
{
|
||||||
return auth('backend')->check();
|
return auth('backend')->check();
|
||||||
}
|
}
|
||||||
|
|
@ -33,13 +33,16 @@ class StoreSliderRequest extends FormRequest
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function prepareForValidation()
|
protected function prepareForValidation(): void
|
||||||
{
|
{
|
||||||
$this->merge([
|
$this->merge([
|
||||||
'link_new_tab' => $this->link_new_tab ? true : false,
|
'link_new_tab' => $this->boolean('link_new_tab'),
|
||||||
'status' => $this->status ? true : false,
|
'status' => $this->boolean('status'),
|
||||||
'publish_at' => $this->publish_at ? \str_replace('T', ' ', $this->publish_at) : null,
|
'publish_at' => $this->input('publish_at') ? \str_replace('T', ' ', $this->input('publish_at')) : null,
|
||||||
'unpublish_at' => $this->unpublish_at ? \str_replace('T', ' ', $this->unpublish_at) : null,
|
'unpublish_at' => $this->input('unpublish_at') ?
|
||||||
|
\str_replace('T', ' ', $this->input('unpublish_at')) :
|
||||||
|
null,
|
||||||
|
'locales' => \collect($this->input('locales'))->filter()->unique()->all()
|
||||||
]);
|
]);
|
||||||
$this->mergePicture('picture');
|
$this->mergePicture('picture');
|
||||||
}
|
}
|
||||||
|
|
@ -49,21 +52,23 @@ class StoreSliderRequest extends FormRequest
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function rules()
|
public function rules(): array
|
||||||
{
|
{
|
||||||
$rules = [
|
$rules = [
|
||||||
'type' => [new Enum(TypeEnum::class)],
|
'type' => [new Enum(TypeEnum::class)],
|
||||||
'title' => 'required|min:3|max:70',
|
'title' => 'required|min:3|max:70',
|
||||||
'subtitle' => 'required|min:3|max:70',
|
'subtitle' => 'required|min:3|max:70',
|
||||||
'description' => 'required|string|min:15',
|
'description' => 'required|string|min:15',
|
||||||
'link' => 'required|url',
|
'link' => 'required|url',
|
||||||
'link_title' => 'required|min:3|max:255',
|
'link_title' => 'required|min:3|max:255',
|
||||||
'link_new_tab' => 'required|boolean',
|
'link_new_tab' => 'required|boolean',
|
||||||
'picture_alt' => 'required|min:3|max:255',
|
'picture_alt' => 'required|min:3|max:255',
|
||||||
'picture_title' => 'required|min:3|max:255',
|
'picture_title' => 'required|min:3|max:255',
|
||||||
'status' => 'required|boolean',
|
'status' => 'required|boolean',
|
||||||
'publish_at' => 'sometimes|nullable|date',
|
'locales' => 'required|array',
|
||||||
'unpublish_at' => 'sometimes|nullable|date'
|
'locales.*' => ['required', \sprintf('in:%s', \implode(',', \config('app.locales')))],
|
||||||
|
'publish_at' => 'sometimes|nullable|date',
|
||||||
|
'unpublish_at' => 'sometimes|nullable|date'
|
||||||
];
|
];
|
||||||
return \array_merge(
|
return \array_merge(
|
||||||
$rules,
|
$rules,
|
||||||
|
|
@ -76,20 +81,20 @@ class StoreSliderRequest extends FormRequest
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function attributes()
|
public function attributes(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'type' => trans('type of slider'),
|
'type' => trans('type of slider'),
|
||||||
'title' => trans('title of the slide'),
|
'title' => trans('title of the slide'),
|
||||||
'subtitle' => trans('subtitle of the slide'),
|
'subtitle' => trans('subtitle of the slide'),
|
||||||
'description' => trans('description of the slide'),
|
'description' => trans('description of the slide'),
|
||||||
'link' => trans('link of the slide'),
|
'link' => trans('link of the slide'),
|
||||||
'link_title' => trans('title of link'),
|
'link_title' => trans('title of link'),
|
||||||
'link_new_tab' => trans('open the link in the new tab'),
|
'link_new_tab' => trans('open the link in the new tab'),
|
||||||
'picture' => trans('illustration'),
|
'picture' => trans('illustration'),
|
||||||
'picture_alt' => trans('alt attribute of the image'),
|
'picture_alt' => trans('alt attribute of the image'),
|
||||||
'picture_title' => trans('title attribute of the image'),
|
'picture_title' => trans('title attribute of the image'),
|
||||||
'status' => trans('status of the slide'),
|
'status' => trans('status of the slide'),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
66
app/Http/Requests/Bo/StaticPages/UpdateStaticPageRequest.php
Normal file
66
app/Http/Requests/Bo/StaticPages/UpdateStaticPageRequest.php
Normal file
|
|
@ -0,0 +1,66 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests\Bo\StaticPages;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
use Illuminate\Support\Facades\Gate;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
|
class UpdateStaticPageRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function authorize(): bool
|
||||||
|
{
|
||||||
|
return Gate::check('update', $this->route('static_page'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prepare the data for validation.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function prepareForValidation(): void
|
||||||
|
{
|
||||||
|
/** @var \App\Models\StaticPage $staticPageModel */
|
||||||
|
$staticPageModel = request()->route()->parameter('static_page');
|
||||||
|
$this->merge([
|
||||||
|
'content' => (in_array($staticPageModel->type, \App\Enums\StaticPageType::getEditableContentPages()))
|
||||||
|
? Str::of($this->input('content'))->value()
|
||||||
|
: null
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||||
|
*/
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'seo_title' => 'required|min:45|max:70',
|
||||||
|
'seo_description' => 'required|min:50|max:160',
|
||||||
|
'title' => 'required|min:3|max:255',
|
||||||
|
'content' => 'present|string|nullable'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get custom attributes for validator errors.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function attributes(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'seo_title' => trans('validation.custom.seo_title'),
|
||||||
|
'seo_description' => trans('validation.custom.seo_description'),
|
||||||
|
'title' => trans('validation.attributes.title'),
|
||||||
|
'content' => trans('validation.attributes.content'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -14,7 +14,7 @@ class StoreStoreGroupRequest extends FormRequest
|
||||||
*
|
*
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function authorize()
|
public function authorize(): bool
|
||||||
{
|
{
|
||||||
return auth('backend')->check();
|
return auth('backend')->check();
|
||||||
}
|
}
|
||||||
|
|
@ -24,7 +24,7 @@ class StoreStoreGroupRequest extends FormRequest
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function prepareForValidation()
|
protected function prepareForValidation(): void
|
||||||
{
|
{
|
||||||
$this->mergePicture('picture');
|
$this->mergePicture('picture');
|
||||||
}
|
}
|
||||||
|
|
@ -34,7 +34,7 @@ class StoreStoreGroupRequest extends FormRequest
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function rules()
|
public function rules(): array
|
||||||
{
|
{
|
||||||
$rules = [
|
$rules = [
|
||||||
'name' => 'required|min:3|max:255',
|
'name' => 'required|min:3|max:255',
|
||||||
|
|
@ -50,7 +50,7 @@ class StoreStoreGroupRequest extends FormRequest
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function attributes()
|
public function attributes(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'name' => trans('name'),
|
'name' => trans('name'),
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ class UpdateStoreGroupRequest extends StoreStoreGroupRequest
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function rules()
|
public function rules(): array
|
||||||
{
|
{
|
||||||
$rules = [
|
$rules = [
|
||||||
'name' => [
|
'name' => [
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ class StoreStoreRegionRequest extends FormRequest
|
||||||
*
|
*
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function authorize()
|
public function authorize(): bool
|
||||||
{
|
{
|
||||||
return auth('backend')->check();
|
return auth('backend')->check();
|
||||||
}
|
}
|
||||||
|
|
@ -24,7 +24,7 @@ class StoreStoreRegionRequest extends FormRequest
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function prepareForValidation()
|
protected function prepareForValidation(): void
|
||||||
{
|
{
|
||||||
$this->mergePicture('picture');
|
$this->mergePicture('picture');
|
||||||
}
|
}
|
||||||
|
|
@ -34,10 +34,10 @@ class StoreStoreRegionRequest extends FormRequest
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function rules()
|
public function rules(): array
|
||||||
{
|
{
|
||||||
$rules = [
|
$rules = [
|
||||||
'name' => 'required|min:3|max:255',
|
'name' => 'required|min:3|max:255',
|
||||||
'group_id' => 'required|exists:store_groups,id',
|
'group_id' => 'required|exists:store_groups,id',
|
||||||
];
|
];
|
||||||
return \array_merge(
|
return \array_merge(
|
||||||
|
|
@ -51,10 +51,10 @@ class StoreStoreRegionRequest extends FormRequest
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function attributes()
|
public function attributes(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'name' => trans('name'),
|
'name' => trans('name'),
|
||||||
'group_id' => trans('group'),
|
'group_id' => trans('group'),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ class UpdateStoreRegionRequest extends StoreStoreRegionRequest
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function rules()
|
public function rules(): array
|
||||||
{
|
{
|
||||||
$rules = [
|
$rules = [
|
||||||
'name' => [
|
'name' => [
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ class StoreStoreTypeRequest extends FormRequest
|
||||||
*
|
*
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function authorize()
|
public function authorize(): bool
|
||||||
{
|
{
|
||||||
return auth('backend')->check();
|
return auth('backend')->check();
|
||||||
}
|
}
|
||||||
|
|
@ -21,7 +21,7 @@ class StoreStoreTypeRequest extends FormRequest
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function rules()
|
public function rules(): array
|
||||||
{
|
{
|
||||||
$rules = [
|
$rules = [
|
||||||
'name' => 'required|min:3|max:255',
|
'name' => 'required|min:3|max:255',
|
||||||
|
|
@ -36,7 +36,7 @@ class StoreStoreTypeRequest extends FormRequest
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function attributes()
|
public function attributes(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'name' => trans('name'),
|
'name' => trans('name'),
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ class UpdateStoreTypeRequest extends StoreStoreTypeRequest
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function rules()
|
public function rules(): array
|
||||||
{
|
{
|
||||||
$rules = [
|
$rules = [
|
||||||
'name' => [
|
'name' => [
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ class StoreStoreRequest extends FormRequest
|
||||||
*
|
*
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function authorize()
|
public function authorize(): bool
|
||||||
{
|
{
|
||||||
return auth('backend')->check();
|
return auth('backend')->check();
|
||||||
}
|
}
|
||||||
|
|
@ -24,15 +24,15 @@ class StoreStoreRequest extends FormRequest
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function rules()
|
public function rules(): array
|
||||||
{
|
{
|
||||||
$rules = [
|
$rules = [
|
||||||
'state' => 'required|min:3|max:255',
|
'state' => 'required|min:3|max:255',
|
||||||
'type_id' => 'required|exists:store_types,id',
|
'type_id' => 'required|exists:store_types,id',
|
||||||
'street' => 'required|min:3|max:255',
|
'street' => 'required|min:3|max:255',
|
||||||
'zipcode' => 'required|min:0|max:5',
|
'zipcode' => 'required|min:0|max:5',
|
||||||
'city' => 'required|min:3|max:255',
|
'city' => 'required|min:3|max:255',
|
||||||
'latitude' => 'required|between:-90,90|decimal:0,8',
|
'latitude' => 'required|between:-90,90|decimal:0,8',
|
||||||
'longitude' => 'required|between:-180,180|decimal:0,8',
|
'longitude' => 'required|between:-180,180|decimal:0,8',
|
||||||
'region_id' => 'required|exists:store_regions,id',
|
'region_id' => 'required|exists:store_regions,id',
|
||||||
];
|
];
|
||||||
|
|
@ -46,15 +46,15 @@ class StoreStoreRequest extends FormRequest
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function attributes()
|
public function attributes(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'state' => trans('State'),
|
'state' => trans('State'),
|
||||||
'type_id' => trans('Type'),
|
'type_id' => trans('Type'),
|
||||||
'street' => trans('Street'),
|
'street' => trans('Street'),
|
||||||
'zipcode' => trans('Zipcode'),
|
'zipcode' => trans('Zipcode'),
|
||||||
'city' => trans('City'),
|
'city' => trans('City'),
|
||||||
'latitude' => trans('Latitude'),
|
'latitude' => trans('Latitude'),
|
||||||
'longitude' => trans('Longitude'),
|
'longitude' => trans('Longitude'),
|
||||||
'region_id' => trans('Region'),
|
'region_id' => trans('Region'),
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,8 @@ namespace App\Http\Requests\Bo;
|
||||||
|
|
||||||
use App\Enums\InputType;
|
use App\Enums\InputType;
|
||||||
use App\Lib\Helpers\ToolboxHelper;
|
use App\Lib\Helpers\ToolboxHelper;
|
||||||
|
use App\Models\Concept;
|
||||||
|
use App\Models\News;
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
use Illuminate\Validation\ValidationException;
|
use Illuminate\Validation\ValidationException;
|
||||||
|
|
||||||
|
|
@ -21,7 +23,7 @@ abstract class UpdateMiniCrudRequest extends FormRequest
|
||||||
*
|
*
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function authorize()
|
public function authorize(): bool
|
||||||
{
|
{
|
||||||
return auth('backend')->check();
|
return auth('backend')->check();
|
||||||
}
|
}
|
||||||
|
|
@ -30,14 +32,24 @@ abstract class UpdateMiniCrudRequest extends FormRequest
|
||||||
* Get the validation rules that apply to the request.
|
* Get the validation rules that apply to the request.
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
* @phpcs:disable Generic.Metrics.CyclomaticComplexity.TooHigh
|
* @phpcs:disable Generic.Metrics.CyclomaticComplexity.MaxExceeded
|
||||||
* @phpcs:disable Generic.Metrics.NestingLevel.TooHigh
|
* @phpcs:disable Generic.Metrics.NestingLevel.TooHigh
|
||||||
|
* @phpcs:disable Generic.Metrics.CyclomaticComplexity.MaxExceeded
|
||||||
*/
|
*/
|
||||||
public function rules()
|
public function rules(): array
|
||||||
{
|
{
|
||||||
// phpcs:enable
|
// phpcs:enable
|
||||||
$rules = [];
|
$rules = [];
|
||||||
foreach ($this->{$this->modelName}->data as $iptName => $input) {
|
$data = $this->{$this->modelName}->data ?? null;
|
||||||
|
if (!$data and $this->route()->getName() === 'bo.concepts.store') {
|
||||||
|
$data = Concept::getEmptyData();
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
!$data and $this->route()->getName() === 'bo.news.store'
|
||||||
|
) {
|
||||||
|
$data = News::getEmptyData();
|
||||||
|
}
|
||||||
|
foreach ($data as $iptName => $input) {
|
||||||
$input = \json_decode(\json_encode($input), true);
|
$input = \json_decode(\json_encode($input), true);
|
||||||
switch ($input['inputType']) {
|
switch ($input['inputType']) {
|
||||||
case InputType::number->value:
|
case InputType::number->value:
|
||||||
|
|
@ -80,7 +92,7 @@ abstract class UpdateMiniCrudRequest extends FormRequest
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return $rule;
|
return $rule;
|
||||||
});
|
})->all();
|
||||||
$rules = array_merge($rules, [
|
$rules = array_merge($rules, [
|
||||||
"data.$iptName.value" => $mergeRules
|
"data.$iptName.value" => $mergeRules
|
||||||
]);
|
]);
|
||||||
|
|
@ -100,33 +112,24 @@ abstract class UpdateMiniCrudRequest extends FormRequest
|
||||||
}) : $input['dimensions'];
|
}) : $input['dimensions'];
|
||||||
|
|
||||||
// * Adapt dimensions
|
// * Adapt dimensions
|
||||||
$sizes = (object)[
|
$sizes = (object) [
|
||||||
'minHeight' => $dim['height'],
|
'minHeight' => $dim['height'],
|
||||||
'maxHeight' => $dim['height'],
|
'maxHeight' => $dim['height'],
|
||||||
'minWith' => $dim['width'],
|
'minWith' => $dim['width'],
|
||||||
'maxWith' => $dim['width'],
|
'maxWith' => $dim['width'],
|
||||||
];
|
];
|
||||||
$rules = array_merge($rules, [
|
$rules = array_merge($rules, [
|
||||||
"data.$iptName.value" => [
|
"data.$iptName.value" => $this->compileValidate(
|
||||||
function (string $attribute, $value, callable $fail) use ($sizes) {
|
$required,
|
||||||
return ToolboxHelper::validatePicture($attribute, $value, $fail, $sizes);
|
|
||||||
}
|
|
||||||
],
|
|
||||||
$this->compileValidate(
|
|
||||||
implode('|', [
|
|
||||||
$required,
|
|
||||||
'image',
|
|
||||||
'mimes:png,jpg,jpeg',
|
|
||||||
sprintf(
|
|
||||||
'dimensions:%s=%d,%s=%d',
|
|
||||||
$max ? 'max_height' : 'height',
|
|
||||||
$dim['height'],
|
|
||||||
$max ? 'max_width' : 'width',
|
|
||||||
$dim['width']
|
|
||||||
)
|
|
||||||
]),
|
|
||||||
$input
|
$input
|
||||||
),
|
),
|
||||||
|
"data.$iptName.value" => [
|
||||||
|
function (string $attribute, $value, callable $fail) use ($sizes) {
|
||||||
|
if ($value) {
|
||||||
|
ToolboxHelper::validatePicture($attribute, $value, $fail, $sizes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
"data.$iptName.alt" => $this->compileValidate("$required|string|min:5", $input),
|
"data.$iptName.alt" => $this->compileValidate("$required|string|min:5", $input),
|
||||||
"data.$iptName.title" => $this->compileValidate("$required|string|min:5", $input)
|
"data.$iptName.title" => $this->compileValidate("$required|string|min:5", $input)
|
||||||
]);
|
]);
|
||||||
|
|
@ -170,9 +173,11 @@ abstract class UpdateMiniCrudRequest extends FormRequest
|
||||||
* @param string|array $inputTypeValidate
|
* @param string|array $inputTypeValidate
|
||||||
* @param array $input
|
* @param array $input
|
||||||
* @return array
|
* @return array
|
||||||
|
* @phpcs:disable Generic.Metrics.CyclomaticComplexity.TooHigh
|
||||||
*/
|
*/
|
||||||
public function compileValidate(string|array $inputTypeValidate, array $input): array
|
public function compileValidate(string|array $inputTypeValidate, array $input): array
|
||||||
{
|
{
|
||||||
|
// phpcs:enable
|
||||||
if (\is_string($inputTypeValidate)) {
|
if (\is_string($inputTypeValidate)) {
|
||||||
$inputTypeValidate = explode('|', $inputTypeValidate);
|
$inputTypeValidate = explode('|', $inputTypeValidate);
|
||||||
}
|
}
|
||||||
|
|
@ -185,36 +190,46 @@ abstract class UpdateMiniCrudRequest extends FormRequest
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$test = \collect($inputTypeValidate)->all();
|
$rules = \collect($inputTypeValidate)->unique()->sort(function ($valueA, $valueB) {
|
||||||
$test = \collect($inputTypeValidate)->sort(function ($valueA, $valueB) {
|
$valueA = $this->ruleHasToComeFirst($valueA);
|
||||||
$valueA = $this->ruleHasToComeFirst($valueA) ? 0 : 2;
|
$valueB = $this->ruleHasToComeFirst($valueB);
|
||||||
$valueB = $this->ruleHasToComeFirst($valueB) ? 1 : 2;
|
|
||||||
return $valueA - $valueB;
|
return $valueA - $valueB;
|
||||||
})->unique()->all();
|
});
|
||||||
|
|
||||||
return \collect($inputTypeValidate)->unique()->sort(function ($valueA, $valueB) {
|
$hasRequire = $rules->first(fn ($rule) => $rule === 'required') ? true : false;
|
||||||
$valueA = $this->ruleHasToComeFirst($valueA) ? 0 : 2;
|
$hasRequireCond = $rules->first(fn ($rule) => \strpos($rule, 'required_') !== false) ? true : false;
|
||||||
$valueB = $this->ruleHasToComeFirst($valueB) ? 1 : 2;
|
$hasNullable = $rules->first(fn ($rule) => \strpos($rule, 'nullable') !== false) ? true : false;
|
||||||
return $valueA - $valueB;
|
$hasSometime = $rules->first(fn ($rule) => \strpos($rule, 'sometimes') !== false) ? true : false;
|
||||||
})->all();
|
$hasPresent = $rules->first(fn ($rule) => \strpos($rule, 'present') !== false) ? true : false;
|
||||||
|
|
||||||
|
if ($hasRequire and ($hasRequireCond or $hasNullable or $hasSometime or $hasPresent)) {
|
||||||
|
$rules = $rules->reject(fn ($rule) => $rule === 'required');
|
||||||
|
}
|
||||||
|
return $rules->all();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Does the rulle need to come first ?
|
* Does the rulle need to come first ?
|
||||||
*
|
*
|
||||||
* @param string $rule
|
* @param string $rule
|
||||||
* @return boolean
|
* @return integer
|
||||||
*/
|
*/
|
||||||
private function ruleHasToComeFirst(string $rule): bool
|
private function ruleHasToComeFirst(string $rule): int
|
||||||
{
|
{
|
||||||
$rule = \collect(\explode(':', $rule, 1))->filter()->first(null, '');
|
$rule = \collect(\explode(':', $rule, 2))->filter()->first(null, '');
|
||||||
return \collect([
|
$rules = \collect([
|
||||||
'nullable', 'present', 'required', 'required_if',
|
'required_if',
|
||||||
'required_unless', 'required_with', 'required_with_all',
|
'required_unless', 'required_with', 'required_with_all',
|
||||||
'required_without', 'required_without_all', 'required_with_all',
|
'required_without', 'required_without_all', 'required_with_all',
|
||||||
'missing', 'missing_if', 'missing_unless',
|
'missing', 'missing_if', 'missing_unless',
|
||||||
'missing_with', 'missing_with_all',
|
'missing_with', 'missing_with_all',
|
||||||
])->first(fn (string $firstRule) => \strpos($rule, $firstRule) === 0) ? true : false;
|
'nullable', 'sometimes', 'present', 'required'
|
||||||
|
]);
|
||||||
|
$itemKey = $rules->search(fn (string $firstRule) => \strpos($rule, $firstRule) === 0);
|
||||||
|
if (\is_bool($itemKey)) {
|
||||||
|
return $rules->count() + 1;
|
||||||
|
}
|
||||||
|
return $itemKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -18,18 +18,6 @@ class ContactRequest extends FormRequest
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Prepare the data for validation.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function prepareForValidation(): void
|
|
||||||
{
|
|
||||||
$this->merge([
|
|
||||||
'terms' => $this->terms ? true : false
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the validation rules that apply to the request.
|
* Get the validation rules that apply to the request.
|
||||||
*
|
*
|
||||||
|
|
@ -38,12 +26,11 @@ class ContactRequest extends FormRequest
|
||||||
public function rules(): array
|
public function rules(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'first_name' => 'required|min:1',
|
'first_name' => 'required|min:1',
|
||||||
'last_name' => 'required|min:1',
|
'last_name' => 'required|min:1',
|
||||||
'email' => 'required|email:rfc,spoof,dns,strict',
|
'email' => 'required|email:rfc,spoof,dns,strict',
|
||||||
'message' => 'required|string|min:10',
|
'message' => 'required|string|min:10',
|
||||||
'terms' => 'accepted',
|
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed
|
||||||
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
|
|
||||||
'g-recaptcha-response' => function (string $attribute, mixed $value, \Closure $fail) {
|
'g-recaptcha-response' => function (string $attribute, mixed $value, \Closure $fail) {
|
||||||
try {
|
try {
|
||||||
ToolboxHelper::validateRecaptcha($this, \config('services.google.recaptcha.version'));
|
ToolboxHelper::validateRecaptcha($this, \config('services.google.recaptcha.version'));
|
||||||
|
|
|
||||||
|
|
@ -19,14 +19,14 @@ class StoreFinderResource extends ResourceCollection
|
||||||
{
|
{
|
||||||
// phpcs:enable
|
// phpcs:enable
|
||||||
return $this->collection->map(fn (Store $store) => [
|
return $this->collection->map(fn (Store $store) => [
|
||||||
'name' => $store->storeRegion->storeGroup->name,
|
'name' => $store->storeRegion->storeGroup->name,
|
||||||
'type' => $store->storeType->name,
|
'type' => $store->storeType->name,
|
||||||
'street' => $store->street,
|
'street' => $store->street,
|
||||||
'zipcode' => $store->zipcode,
|
'zipcode' => $store->zipcode,
|
||||||
'city' => $store->city,
|
'city' => $store->city,
|
||||||
'latitude' => $store->latitude,
|
'latitude' => $store->latitude,
|
||||||
'longitude' => $store->longitude,
|
'longitude' => $store->longitude,
|
||||||
'picture' => $store->storeRegion->storeGroup->picture,
|
'picture' => $store->storeRegion->storeGroup->picture,
|
||||||
])->all();
|
])->all();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
51
app/Interfaces/Models/Publishable.php
Normal file
51
app/Interfaces/Models/Publishable.php
Normal file
|
|
@ -0,0 +1,51 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Interfaces\Models;
|
||||||
|
|
||||||
|
interface Publishable
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Get status attribute.
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function getStatus(): bool;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set status attribute.
|
||||||
|
*
|
||||||
|
* @param boolean $status
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setStatus(bool $status): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get publish_at attribute.
|
||||||
|
*
|
||||||
|
* @return \Carbon\Carbon|null
|
||||||
|
*/
|
||||||
|
public function getPublishAt(): ?\Carbon\Carbon;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set publish_at attribute.
|
||||||
|
*
|
||||||
|
* @param \Carbon\Carbon|null $date
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setPublishAt(?\Carbon\Carbon $date): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get unpublish_at attribute.
|
||||||
|
*
|
||||||
|
* @return \Carbon\Carbon|null
|
||||||
|
*/
|
||||||
|
public function getUnpublishAt(): ?\Carbon\Carbon;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set unpublish_at attribute.
|
||||||
|
*
|
||||||
|
* @param \Carbon\Carbon|null $date
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setUnpublishAt(?\Carbon\Carbon $date): void;
|
||||||
|
}
|
||||||
39
app/Jobs/NewsStatusUpdate.php
Normal file
39
app/Jobs/NewsStatusUpdate.php
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Jobs;
|
||||||
|
|
||||||
|
use App\Models\News;
|
||||||
|
use Illuminate\Support\Carbon;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update status attribute reading its
|
||||||
|
* publish_at and unpublish_at attributes.
|
||||||
|
*/
|
||||||
|
class NewsStatusUpdate
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Called when the job will be executed.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
/** @var \Illuminate\Database\Eloquent\Collection<array-key, \App\Models\News> */
|
||||||
|
$newsListToPublish = News::query()->where('publish_at', '<=', Carbon::now()->toDateTime())
|
||||||
|
->where('status', false)->get();
|
||||||
|
Log::debug(__CLASS__ . " news to publish " . $newsListToPublish->count());
|
||||||
|
foreach ($newsListToPublish as $news) {
|
||||||
|
$news->status = true;
|
||||||
|
$news->saveOrFail();
|
||||||
|
}
|
||||||
|
/** @var \Illuminate\Database\Eloquent\Collection<array-key, \App\Models\News> */
|
||||||
|
$newsListToUnPublish = News::query()->where('unpublish_at', '<=', Carbon::now()->toDateTime())
|
||||||
|
->where('status', true)->get();
|
||||||
|
Log::debug(__CLASS__ . " news to unpublish " . $newsListToPublish->count());
|
||||||
|
foreach ($newsListToUnPublish as $news) {
|
||||||
|
$news->status = false;
|
||||||
|
$news->saveOrFail();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -19,7 +19,8 @@ class SlidersStatusUpdate
|
||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
$slidersToPublish = Slider::where('publish_at', '<=', Carbon::now()->toDateTime())
|
/** @var \Illuminate\Database\Eloquent\Collection<array-key, \App\Models\Slider> */
|
||||||
|
$slidersToPublish = Slider::query()->where('publish_at', '<=', Carbon::now()->toDateTime())
|
||||||
->whereNotNull('publish_at')
|
->whereNotNull('publish_at')
|
||||||
->where('status', false)->get();
|
->where('status', false)->get();
|
||||||
Log::debug(__CLASS__ . " sliders to publish " . $slidersToPublish->count());
|
Log::debug(__CLASS__ . " sliders to publish " . $slidersToPublish->count());
|
||||||
|
|
@ -28,7 +29,9 @@ class SlidersStatusUpdate
|
||||||
$slider->status = true;
|
$slider->status = true;
|
||||||
$slider->saveOrFail();
|
$slider->saveOrFail();
|
||||||
}
|
}
|
||||||
$slidersToUnPublish = Slider::where('unpublish_at', '<=', Carbon::now()->toDateTime())
|
|
||||||
|
/** @var \Illuminate\Database\Eloquent\Collection<array-key, \App\Models\Slider> */
|
||||||
|
$slidersToUnPublish = Slider::query()->where('unpublish_at', '<=', Carbon::now()->toDateTime())
|
||||||
->whereNotNull('unpublish_at')
|
->whereNotNull('unpublish_at')
|
||||||
->where('status', true)->get();
|
->where('status', true)->get();
|
||||||
Log::debug(__CLASS__ . " sliders to unpublish " . $slidersToPublish->count());
|
Log::debug(__CLASS__ . " sliders to unpublish " . $slidersToPublish->count());
|
||||||
|
|
|
||||||
|
|
@ -145,7 +145,7 @@ class ExceptionsHelper
|
||||||
$traceStr .= self::handleArgs($stack);
|
$traceStr .= self::handleArgs($stack);
|
||||||
}
|
}
|
||||||
$traceStr .= ")\n";
|
$traceStr .= ")\n";
|
||||||
} elseif (isset($stack['function'])) {
|
} else {
|
||||||
$traceStr .= "{$stack['function']}(";
|
$traceStr .= "{$stack['function']}(";
|
||||||
if (isset($stack['args'])) {
|
if (isset($stack['args'])) {
|
||||||
$traceStr .= self::handleArgs($stack);
|
$traceStr .= self::handleArgs($stack);
|
||||||
|
|
|
||||||
|
|
@ -118,7 +118,7 @@ class FileStorageHelper
|
||||||
);
|
);
|
||||||
|
|
||||||
return str_replace('/private/', '', $newPath);
|
return str_replace('/private/', '', $newPath);
|
||||||
}//end if
|
} //end if
|
||||||
if (\is_object($file) and $file instanceof \SplFileInfo) {
|
if (\is_object($file) and $file instanceof \SplFileInfo) {
|
||||||
/** @var \SplFileInfo $file */
|
/** @var \SplFileInfo $file */
|
||||||
$filename = $filename ?: $file->getBaseName();
|
$filename = $filename ?: $file->getBaseName();
|
||||||
|
|
@ -309,7 +309,6 @@ class FileStorageHelper
|
||||||
$private ? 'app/private/modelfiles' : 'app/public/modelfiles',
|
$private ? 'app/private/modelfiles' : 'app/public/modelfiles',
|
||||||
$tableName,
|
$tableName,
|
||||||
$filename,
|
$filename,
|
||||||
$private
|
|
||||||
);
|
);
|
||||||
$filename = self::getFileUniqueName($folderPath, $filename);
|
$filename = self::getFileUniqueName($folderPath, $filename);
|
||||||
return "{$folderPath}/{$filename}";
|
return "{$folderPath}/{$filename}";
|
||||||
|
|
@ -404,7 +403,7 @@ class FileStorageHelper
|
||||||
$filename = Str::of($filename)->ltrim('.-');
|
$filename = Str::of($filename)->ltrim('.-');
|
||||||
// * Optional beautification
|
// * Optional beautification
|
||||||
if ($beautify) {
|
if ($beautify) {
|
||||||
$filename = static::beautifyFilename($filename);
|
$filename = self::beautifyFilename($filename);
|
||||||
}
|
}
|
||||||
// * Maximize filename length to 255 bytes http://serverfault.com/a/9548/44086
|
// * Maximize filename length to 255 bytes http://serverfault.com/a/9548/44086
|
||||||
/** @var string */
|
/** @var string */
|
||||||
|
|
|
||||||
|
|
@ -6,22 +6,55 @@ use Carbon\Carbon;
|
||||||
use Illuminate\Contracts\Database\Eloquent\Builder;
|
use Illuminate\Contracts\Database\Eloquent\Builder;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Arr;
|
||||||
use Illuminate\Support\Facades\File;
|
use Illuminate\Support\Facades\File;
|
||||||
use Illuminate\Support\Facades\Http;
|
use Illuminate\Support\Facades\Http;
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
use Illuminate\Support\Facades\Validator;
|
use Illuminate\Support\Facades\Validator;
|
||||||
use Illuminate\Validation\Rule;
|
use Illuminate\Validation\Rule;
|
||||||
use Illuminate\Validation\ValidationException;
|
use Illuminate\Validation\ValidationException;
|
||||||
|
use Symfony\Component\Finder\SplFileInfo;
|
||||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
|
|
||||||
class ToolboxHelper
|
class ToolboxHelper
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @param array<int|string, mixed> $array1
|
* Fetch class list from a specific namespace
|
||||||
* @param array<int|string, mixed> $array2
|
|
||||||
*
|
*
|
||||||
* @return array<int|string, mixed>
|
* @param string $namespace
|
||||||
|
* @return array<string> An array of classe namespaces
|
||||||
|
*/
|
||||||
|
public static function getClassesUsingNamespace(string $namespace): array
|
||||||
|
{
|
||||||
|
return collect(File::files(\app_path(Str::of($namespace)->replaceFirst('\App', ''))))
|
||||||
|
->filter(fn (SplFileInfo $splFileInfo) => $splFileInfo->getExtension() === 'php')
|
||||||
|
->map(fn (SplFileInfo $splFileInfo) => Str::of($splFileInfo->getBasename())
|
||||||
|
->replace('.' . $splFileInfo->getExtension(), '')->prepend("{$namespace}\\"))->all();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all classes from a specific namespace that implement a specific interface
|
||||||
|
*
|
||||||
|
* @param string $namespace
|
||||||
|
* @param string $interface
|
||||||
|
* @return array<string> An array of classe namespaces
|
||||||
|
*/
|
||||||
|
public static function getClassesUsingInterface(string $namespace, string $interface): array
|
||||||
|
{
|
||||||
|
return Arr::where(
|
||||||
|
static::getClassesUsingNamespace($namespace),
|
||||||
|
fn (string $class_namespace) => \collect(class_implements($class_namespace, true))->filter()
|
||||||
|
->contains(fn (string $class_interface) => $class_interface === $interface)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<integer|string, mixed> $array1
|
||||||
|
* @param array<integer|string, mixed> $array2
|
||||||
|
*
|
||||||
|
* @return array<integer|string, mixed>
|
||||||
*/
|
*/
|
||||||
public static function arrayMergeRecursiveDistinct(array &$array1, array &$array2): array
|
public static function arrayMergeRecursiveDistinct(array &$array1, array &$array2): array
|
||||||
{
|
{
|
||||||
|
|
@ -171,11 +204,10 @@ class ToolboxHelper
|
||||||
$url = $match;
|
$url = $match;
|
||||||
try {
|
try {
|
||||||
$request = Request::create($url);
|
$request = Request::create($url);
|
||||||
// If a route is match then it do not throws exception.
|
// Assert route matches existing routes.
|
||||||
if (
|
$routes->match($request);
|
||||||
\parse_url(config('app.url'), \PHP_URL_HOST) === \parse_url($url, \PHP_URL_HOST) &&
|
// ? Is url internal ?
|
||||||
$routes->match($request)
|
if (\parse_url(config('app.url'), \PHP_URL_HOST) === \parse_url($url, \PHP_URL_HOST)) {
|
||||||
) {
|
|
||||||
// Removes the matched url.
|
// Removes the matched url.
|
||||||
throw ValidationException::withMessages([
|
throw ValidationException::withMessages([
|
||||||
$field => trans(
|
$field => trans(
|
||||||
|
|
@ -201,14 +233,14 @@ class ToolboxHelper
|
||||||
* @param array|string $replace
|
* @param array|string $replace
|
||||||
* @param array|string $subject
|
* @param array|string $subject
|
||||||
* @param integer $count
|
* @param integer $count
|
||||||
* @return array|string
|
* @return array|string|false
|
||||||
*/
|
*/
|
||||||
public static function mbReplace(
|
public static function mbReplace(
|
||||||
array|string $search,
|
array|string $search,
|
||||||
array|string $replace,
|
array|string $replace,
|
||||||
array|string $subject,
|
array|string $subject,
|
||||||
int &$count = 0
|
int &$count = 0
|
||||||
): array|string {
|
): array|string|false {
|
||||||
if (!is_array($search) && is_array($replace)) {
|
if (!is_array($search) && is_array($replace)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -285,9 +317,12 @@ class ToolboxHelper
|
||||||
public static function getOriginal(Model $model, string $attribute): mixed
|
public static function getOriginal(Model $model, string $attribute): mixed
|
||||||
{
|
{
|
||||||
if (\in_array('Spatie\Translatable\HasTranslations', \class_uses_recursive($model))) {
|
if (\in_array('Spatie\Translatable\HasTranslations', \class_uses_recursive($model))) {
|
||||||
|
// @phpstan-ignore-next-line
|
||||||
return $model->getTranslation(
|
return $model->getTranslation(
|
||||||
$attribute,
|
$attribute,
|
||||||
|
// @phpstan-ignore-next-line
|
||||||
$model->getLocale(),
|
$model->getLocale(),
|
||||||
|
// @phpstan-ignore-next-line
|
||||||
$model->useFallbackLocale()
|
$model->useFallbackLocale()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -357,55 +392,55 @@ class ToolboxHelper
|
||||||
/**
|
/**
|
||||||
* Convert deeply an object to array
|
* Convert deeply an object to array
|
||||||
*
|
*
|
||||||
* @param array|object $input
|
* @param mixed $input
|
||||||
* @return array
|
* @return array
|
||||||
* @throws \RuntimeException If $input var is a scalar value.
|
* @throws \RuntimeException If $input var is a scalar value.
|
||||||
*/
|
*/
|
||||||
public static function objectToArray($input): array
|
public static function objectToArray(mixed $input): array
|
||||||
{
|
{
|
||||||
// Only process if it's an object or array being passed to the function.
|
// Only process if it's an object or array being passed to the function.
|
||||||
if (is_object($input) or is_array($input)) {
|
if (!(is_object($input) or is_array($input))) {
|
||||||
$ret = (array)$input;
|
|
||||||
foreach ($ret as &$item) {
|
|
||||||
// Recursively process EACH element only if not scalar.
|
|
||||||
$item = (is_object($item) or is_array($item)) ?
|
|
||||||
self::objectToArray($item) : $item;
|
|
||||||
}
|
|
||||||
return $ret;
|
|
||||||
} else {
|
|
||||||
throw new \RuntimeException('Cannot handle $input of type ' . \gettype($input));
|
throw new \RuntimeException('Cannot handle $input of type ' . \gettype($input));
|
||||||
}
|
}
|
||||||
|
$ret = (array) $input;
|
||||||
|
foreach ($ret as &$item) {
|
||||||
|
// Recursively process EACH element only if not scalar.
|
||||||
|
$item = (is_object($item) or is_array($item)) ?
|
||||||
|
self::objectToArray($item) : $item;
|
||||||
|
}
|
||||||
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert deeply an array to object
|
* Convert deeply an array to object
|
||||||
*
|
*
|
||||||
* @param array|object $input
|
* @param mixed $input
|
||||||
* @return object
|
* @return object
|
||||||
* @throws \RuntimeException If $input var is a scalar value.
|
* @throws \RuntimeException If $input var is a scalar value.
|
||||||
*/
|
*/
|
||||||
public static function arrayToObject($input): object
|
public static function arrayToObject(mixed $input): object
|
||||||
{
|
{
|
||||||
// Only process if it's an object or array being passed to the function.
|
// Only process if it's an object or array being passed to the function.
|
||||||
if (is_object($input) or is_array($input)) {
|
if (!(is_object($input) or is_array($input))) {
|
||||||
$ret = (object)$input;
|
|
||||||
foreach ($ret as &$item) {
|
|
||||||
// Recursively process EACH element only if not scalar.
|
|
||||||
$item = (is_object($item) or is_array($item)) ?
|
|
||||||
self::arrayToObject($item) : $item;
|
|
||||||
}
|
|
||||||
return $ret;
|
|
||||||
} else {
|
|
||||||
throw new \RuntimeException('Cannot handle $input of type ' . \gettype($input));
|
throw new \RuntimeException('Cannot handle $input of type ' . \gettype($input));
|
||||||
}
|
}
|
||||||
|
$ret = (object) $input;
|
||||||
|
foreach ($ret as &$item) {
|
||||||
|
// Recursively process EACH element only if not scalar.
|
||||||
|
$item = (is_object($item) or is_array($item)) ?
|
||||||
|
self::arrayToObject($item) : $item;
|
||||||
|
}
|
||||||
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate picture
|
* Validate picture
|
||||||
*
|
*
|
||||||
* @param string $attribute
|
* @param string $attribute
|
||||||
* @param string|null $value
|
* @param string|null $value
|
||||||
* @param callback $fail
|
* @param callable $fail
|
||||||
* @param object $sizes
|
* @param object $sizes
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
|
|
@ -428,7 +463,7 @@ class ToolboxHelper
|
||||||
'attribute' => $attribute
|
'attribute' => $attribute
|
||||||
]));
|
]));
|
||||||
}
|
}
|
||||||
if (!($dimensions = \getimagesize($fileFullPath)) or !isset($dimensions[0]) or !isset($dimensions[1])) {
|
if (!($dimensions = \getimagesize($fileFullPath))) {
|
||||||
$fail(trans(':attribute impossible de valider les dimensions', [
|
$fail(trans(':attribute impossible de valider les dimensions', [
|
||||||
'attribute' => $attribute
|
'attribute' => $attribute
|
||||||
]));
|
]));
|
||||||
|
|
|
||||||
|
|
@ -46,10 +46,9 @@ class ContactMessageReceived extends Mailable
|
||||||
'no-reply@nature-and-respect.com',
|
'no-reply@nature-and-respect.com',
|
||||||
'Kontaktformular'
|
'Kontaktformular'
|
||||||
),
|
),
|
||||||
to: new Address(
|
to: [
|
||||||
'contact@nature-and-respect.com',
|
'contact@nature-and-respect.com',
|
||||||
'contact@nature-and-respect.com'
|
]
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,11 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use Illuminate\Validation\Rules\Enum;
|
use Illuminate\Validation\Rules\Enum;
|
||||||
|
use Spatie\Sitemap\Contracts\Sitemapable;
|
||||||
|
use Uwil\Seo\Laravel\Interfaces\SeoInterface;
|
||||||
|
use Uwil\Seo\Laravel\Objects\SeoItem;
|
||||||
|
use Uwil\Seo\Laravel\Traits\SeoTrait;
|
||||||
|
use Uwil\SitemapGenerator\Lib\SitemapHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property string $seo_title
|
* @property string $seo_title
|
||||||
|
|
@ -30,15 +35,18 @@ use Illuminate\Validation\Rules\Enum;
|
||||||
* @property string $created_at
|
* @property string $created_at
|
||||||
* @property string $updated_at
|
* @property string $updated_at
|
||||||
*/
|
*/
|
||||||
class Concept extends Model
|
class Concept extends Model implements SeoInterface, Sitemapable
|
||||||
{
|
{
|
||||||
use HasFactory;
|
use HasFactory;
|
||||||
use HasTranslations;
|
use HasTranslations;
|
||||||
use IsCachedAsCollection;
|
use IsCachedAsCollection;
|
||||||
use MiniCrudModel;
|
use MiniCrudModel;
|
||||||
|
use SeoTrait;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array
|
* The attributes that are mass assignable.
|
||||||
|
*
|
||||||
|
* @var array<int, string>
|
||||||
*/
|
*/
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'seo_title',
|
'seo_title',
|
||||||
|
|
@ -61,7 +69,7 @@ class Concept extends Model
|
||||||
/**
|
/**
|
||||||
* The attributes that should be cast.
|
* The attributes that should be cast.
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array<string, string>
|
||||||
*/
|
*/
|
||||||
protected $casts = [
|
protected $casts = [
|
||||||
'data' => 'object',
|
'data' => 'object',
|
||||||
|
|
@ -71,7 +79,7 @@ class Concept extends Model
|
||||||
/**
|
/**
|
||||||
* The translatable columns.
|
* The translatable columns.
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array<string>
|
||||||
*/
|
*/
|
||||||
public $translatable = [
|
public $translatable = [
|
||||||
'data',
|
'data',
|
||||||
|
|
@ -133,10 +141,10 @@ class Concept extends Model
|
||||||
/**
|
/**
|
||||||
* Common methods function.
|
* Common methods function.
|
||||||
*
|
*
|
||||||
* @param Model $model
|
* @param self $model
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
private static function manageFields(Model $model)
|
private static function manageFields(self $model)
|
||||||
{
|
{
|
||||||
self::setSlug($model);
|
self::setSlug($model);
|
||||||
ToolboxHelper::assertNoInternalBoUrls('description', $model->description);
|
ToolboxHelper::assertNoInternalBoUrls('description', $model->description);
|
||||||
|
|
@ -146,11 +154,11 @@ class Concept extends Model
|
||||||
/**
|
/**
|
||||||
* Set the slug.
|
* Set the slug.
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Database\Eloquent\Model $model
|
* @param self $model
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
private static function setSlug(Model $model)
|
private static function setSlug(self $model)
|
||||||
{
|
{
|
||||||
$model->slug = Str::slug($model->name);
|
$model->slug = Str::slug($model->name);
|
||||||
}
|
}
|
||||||
|
|
@ -158,10 +166,10 @@ class Concept extends Model
|
||||||
/**
|
/**
|
||||||
* Set order after the last element of the list.
|
* Set order after the last element of the list.
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Database\Eloquent\Model $model
|
* @param self $model
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
private static function setOrder(Model $model): void
|
private static function setOrder(self $model): void
|
||||||
{
|
{
|
||||||
$model->order = \intval(self::query()->max('order')) + 1;
|
$model->order = \intval(self::query()->max('order')) + 1;
|
||||||
}
|
}
|
||||||
|
|
@ -199,11 +207,13 @@ class Concept extends Model
|
||||||
string $imgAlt = '',
|
string $imgAlt = '',
|
||||||
string $imgTitle = ''
|
string $imgTitle = ''
|
||||||
) {
|
) {
|
||||||
$color = $color ?: \collect(ColorsEnum::cases())->random()->value;
|
/** @var \App\Enums\Concepts\ColorsEnum */
|
||||||
$data = [];
|
$defaultColor = \collect(ColorsEnum::cases())->random();
|
||||||
|
$color = $color ?: $defaultColor->value;
|
||||||
|
$data = [];
|
||||||
for ($i = 1; $i <= 6; $i++) {
|
for ($i = 1; $i <= 6; $i++) {
|
||||||
$data = self::emptyDataBloc(
|
$data = self::emptyDataBloc(
|
||||||
$i,
|
\strval($i),
|
||||||
$data,
|
$data,
|
||||||
$title,
|
$title,
|
||||||
$color,
|
$color,
|
||||||
|
|
@ -250,13 +260,17 @@ class Concept extends Model
|
||||||
'label' => "Bloc {$index} - Title",
|
'label' => "Bloc {$index} - Title",
|
||||||
'inputType' => InputType::string->value,
|
'inputType' => InputType::string->value,
|
||||||
'value' => $title,
|
'value' => $title,
|
||||||
'validate' => 'required|min:4|max:100'
|
'validate' => ($index > 4 ? "required_if:bloc_{$index}_use_bloc,true" : 'required') . '|min:4|max:100'
|
||||||
];
|
];
|
||||||
$data["bloc_{$index}_color"] = [
|
$data["bloc_{$index}_color"] = [
|
||||||
'label' => "Bloc {$index} - Color",
|
'label' => "Bloc {$index} - Color",
|
||||||
'inputType' => InputType::selectEnum->value,
|
'inputType' => InputType::selectEnum->value,
|
||||||
'value' => $color,
|
'value' => $color,
|
||||||
'validate' => ['required', 'integer', new Enum(ColorsEnum::class)]
|
'validate' => [
|
||||||
|
($index > 4 ? "required_if:bloc_{$index}_use_bloc,true" : 'required'),
|
||||||
|
'integer',
|
||||||
|
new Enum(ColorsEnum::class)
|
||||||
|
]
|
||||||
];
|
];
|
||||||
$data["bloc_{$index}_text"] = [
|
$data["bloc_{$index}_text"] = [
|
||||||
'label' => "Bloc {$index} - Text",
|
'label' => "Bloc {$index} - Text",
|
||||||
|
|
@ -271,7 +285,7 @@ class Concept extends Model
|
||||||
'alt' => $imgAlt,
|
'alt' => $imgAlt,
|
||||||
'title' => $imgTitle,
|
'title' => $imgTitle,
|
||||||
'value' => $img,
|
'value' => $img,
|
||||||
'validate' => "required_if:data.bloc_{$index}_has_video.value,false",
|
'validate' => ($index > 4 ? "required_if:bloc_{$index}_use_bloc,true" : '') . '',
|
||||||
];
|
];
|
||||||
|
|
||||||
$data["bloc_{$index}_video"] = [
|
$data["bloc_{$index}_video"] = [
|
||||||
|
|
@ -280,7 +294,7 @@ class Concept extends Model
|
||||||
'value' => '',
|
'value' => '',
|
||||||
// phpcs:ignore Generic.Files.LineLength.TooLong
|
// phpcs:ignore Generic.Files.LineLength.TooLong
|
||||||
'validate' => [
|
'validate' => [
|
||||||
'required_if:data.bloc_{$i}_has_video.value,true',
|
"required_if:data.bloc_{$index}_has_video.value,true",
|
||||||
'nullable',
|
'nullable',
|
||||||
'regex:%([0-9]{8,10}|[^\"&?\/\s]{11})%i'
|
'regex:%([0-9]{8,10}|[^\"&?\/\s]{11})%i'
|
||||||
],
|
],
|
||||||
|
|
@ -293,6 +307,45 @@ class Concept extends Model
|
||||||
'value' => false,
|
'value' => false,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
if ($index > 4) {
|
||||||
|
$data["bloc_{$index}_title"]['required'] = false;
|
||||||
|
$data["bloc_{$index}_title"]['validate'] .= '|nullable';
|
||||||
|
$data["bloc_{$index}_color"]['required'] = false;
|
||||||
|
$data["bloc_{$index}_text"]['required'] = false;
|
||||||
|
$data["bloc_{$index}_text"]['validate'] .= '|nullable';
|
||||||
|
$data["bloc_{$index}_image"]['required'] = false;
|
||||||
|
$data["bloc_{$index}_image"]['validate'] .= '|nullable';
|
||||||
|
$data["bloc_{$index}_video"]['required'] = false;
|
||||||
|
$data["bloc_{$index}_has_video"]['required'] = false;
|
||||||
|
}
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the SEO object.
|
||||||
|
*
|
||||||
|
* @return \Uwil\Seo\Laravel\Objects\SeoItem
|
||||||
|
*/
|
||||||
|
public function toSeoItem(): \Uwil\Seo\Laravel\Objects\SeoItem
|
||||||
|
{
|
||||||
|
return new SeoItem(
|
||||||
|
\trans($this->getTable()),
|
||||||
|
$this->seo_title,
|
||||||
|
$this->seo_description,
|
||||||
|
true,
|
||||||
|
\route(\config('seo.bo_route_prefix') . $this->getTable() . '.edit', $this),
|
||||||
|
\route(Str::singular($this->getTable()) . '.show', $this)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To sitemap tag .
|
||||||
|
*
|
||||||
|
* @return \Spatie\Sitemap\Tags\Url|string|array
|
||||||
|
*/
|
||||||
|
public function toSitemapTag(): \Spatie\Sitemap\Tags\Url|string|array
|
||||||
|
{
|
||||||
|
return SitemapHelper::generateUrl('concept.show', ['concept' => $this], $this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,6 @@ use Illuminate\Database\Eloquent\Model;
|
||||||
/**
|
/**
|
||||||
* @property integer $part2_product1_id
|
* @property integer $part2_product1_id
|
||||||
* @property integer $part2_product2_id
|
* @property integer $part2_product2_id
|
||||||
* @property string $seo_title
|
|
||||||
* @property string $seo_description
|
|
||||||
* @property string $part1_title
|
* @property string $part1_title
|
||||||
* @property string $part1_subtitle
|
* @property string $part1_subtitle
|
||||||
* @property string $part1_text_1
|
* @property string $part1_text_1
|
||||||
|
|
@ -32,13 +30,13 @@ class Home extends Model
|
||||||
use HasTranslations;
|
use HasTranslations;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array
|
* The attributes that are mass assignable.
|
||||||
|
*
|
||||||
|
* @var array<int, string>
|
||||||
*/
|
*/
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'part2_product1_id',
|
'part2_product1_id',
|
||||||
'part2_product2_id',
|
'part2_product2_id',
|
||||||
'seo_title',
|
|
||||||
'seo_description',
|
|
||||||
'part1_title',
|
'part1_title',
|
||||||
'part1_subtitle',
|
'part1_subtitle',
|
||||||
'part1_text_1',
|
'part1_text_1',
|
||||||
|
|
@ -58,7 +56,7 @@ class Home extends Model
|
||||||
/**
|
/**
|
||||||
* The attributes that should be cast.
|
* The attributes that should be cast.
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array<string, string>
|
||||||
*/
|
*/
|
||||||
protected $casts = [
|
protected $casts = [
|
||||||
'part2_list' => 'array',
|
'part2_list' => 'array',
|
||||||
|
|
@ -70,8 +68,6 @@ class Home extends Model
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public $translatable = [
|
public $translatable = [
|
||||||
'seo_title',
|
|
||||||
'seo_description',
|
|
||||||
'part1_title',
|
'part1_title',
|
||||||
'part1_subtitle',
|
'part1_subtitle',
|
||||||
'part1_text_1',
|
'part1_text_1',
|
||||||
|
|
@ -113,10 +109,10 @@ class Home extends Model
|
||||||
/**
|
/**
|
||||||
* Undocumented function
|
* Undocumented function
|
||||||
*
|
*
|
||||||
* @param Model $model
|
* @param self $model
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
private static function manageFields(Model $model)
|
private static function manageFields(self $model)
|
||||||
{
|
{
|
||||||
ToolboxHelper::assertNoInternalBoUrls('part1_text_1', $model->part1_text_1);
|
ToolboxHelper::assertNoInternalBoUrls('part1_text_1', $model->part1_text_1);
|
||||||
ToolboxHelper::assertNoInternalBoUrls('part1_text_2', $model->part1_text_2);
|
ToolboxHelper::assertNoInternalBoUrls('part1_text_2', $model->part1_text_2);
|
||||||
|
|
|
||||||
344
app/Models/News.php
Normal file
344
app/Models/News.php
Normal file
|
|
@ -0,0 +1,344 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use App\Enums\InputType;
|
||||||
|
use App\Interfaces\Models\Publishable;
|
||||||
|
use App\Lib\Helpers\FileStorageHelper;
|
||||||
|
use App\Lib\Helpers\ToolboxHelper;
|
||||||
|
use App\Traits\Models\HasTranslations;
|
||||||
|
use App\Traits\Models\IsPublishable;
|
||||||
|
use App\Traits\Models\MiniCrudModel;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
use Spatie\SchemaOrg\Schema;
|
||||||
|
use Spatie\Sitemap\Contracts\Sitemapable;
|
||||||
|
use Uwil\SchemaOrg\Laravel\Interfaces\SchemaOrgInterface;
|
||||||
|
use Uwil\SchemaOrg\Laravel\Traits\SchemaOrgTrait;
|
||||||
|
use Uwil\Seo\Laravel\Interfaces\SeoInterface;
|
||||||
|
use Uwil\Seo\Laravel\Objects\SeoItem;
|
||||||
|
use Uwil\Seo\Laravel\Traits\SeoTrait;
|
||||||
|
use Uwil\SitemapGenerator\Lib\SitemapHelper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property string $seo_title
|
||||||
|
* @property string $seo_description
|
||||||
|
* @property string $title
|
||||||
|
* @property string $slug
|
||||||
|
* @property string $subtitle
|
||||||
|
* @property string $content
|
||||||
|
* @property \Illuminate\Support\Collection $picture_list
|
||||||
|
* @property object $data
|
||||||
|
* @property integer $order
|
||||||
|
* @property boolean $status
|
||||||
|
* @property \Carbon\Carbon|null $publish_at
|
||||||
|
* @property \Carbon\Carbon|null $unpublish_at
|
||||||
|
* @property \Carbon\Carbon $created_at
|
||||||
|
* @property \Carbon\Carbon $updated_at
|
||||||
|
*/
|
||||||
|
class News extends Model implements SeoInterface, Publishable, SchemaOrgInterface, Sitemapable
|
||||||
|
{
|
||||||
|
use HasFactory;
|
||||||
|
use HasTranslations;
|
||||||
|
use MiniCrudModel;
|
||||||
|
use SeoTrait;
|
||||||
|
use IsPublishable;
|
||||||
|
use SchemaOrgTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The attributes that are mass assignable.
|
||||||
|
*
|
||||||
|
* @var array<int, string>
|
||||||
|
*/
|
||||||
|
protected $fillable = [
|
||||||
|
'seo_title',
|
||||||
|
'seo_description',
|
||||||
|
'title',
|
||||||
|
'slug',
|
||||||
|
'subtitle',
|
||||||
|
'content',
|
||||||
|
'data',
|
||||||
|
'locales',
|
||||||
|
'order',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The attributes that should be cast.
|
||||||
|
*
|
||||||
|
* @var array<string, string>
|
||||||
|
*/
|
||||||
|
protected $casts = [
|
||||||
|
'data' => 'object',
|
||||||
|
'locales' => 'array',
|
||||||
|
'status' => 'bool',
|
||||||
|
'publish_at' => 'datetime',
|
||||||
|
'unpublish_at' => 'datetime'
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The translatable columns.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
public $translatable = [
|
||||||
|
'seo_title',
|
||||||
|
'seo_description',
|
||||||
|
'title',
|
||||||
|
'slug',
|
||||||
|
'subtitle',
|
||||||
|
'content',
|
||||||
|
'data'
|
||||||
|
];
|
||||||
|
|
||||||
|
// * EVENTS
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Perform any actions required after the model boots.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected static function booted()
|
||||||
|
{
|
||||||
|
static::creating(function (self $model) {
|
||||||
|
// * ASSERTIONS
|
||||||
|
self::assertTitleIsUnique($model->title);
|
||||||
|
ToolboxHelper::assertNoInternalBoUrls('content', $model->content);
|
||||||
|
|
||||||
|
// * TRANSFORMATIONS
|
||||||
|
self::setSlug($model);
|
||||||
|
$model->content = FileStorageHelper::storeModelFilesFromHtml($model, $model->content);
|
||||||
|
$model->makeStatusSense();
|
||||||
|
self::setOrder($model);
|
||||||
|
});
|
||||||
|
static::updating(function (self $model) {
|
||||||
|
// * ASSERTIONS
|
||||||
|
self::assertTitleIsUnique($model->title);
|
||||||
|
ToolboxHelper::assertNoInternalBoUrls('content', $model->content);
|
||||||
|
|
||||||
|
// * TRANSFORMATIONS
|
||||||
|
self::setSlug($model);
|
||||||
|
$model->content = FileStorageHelper::storeModelFilesFromHtml($model, $model->content);
|
||||||
|
$model->makeStatusSense();
|
||||||
|
});
|
||||||
|
static::updated(function (self $model) {
|
||||||
|
FileStorageHelper::removeOldModelFilesFromHtml(
|
||||||
|
$model->content,
|
||||||
|
ToolboxHelper::getOriginal($model, 'content')
|
||||||
|
);
|
||||||
|
});
|
||||||
|
static::deleted(function (self $model) {
|
||||||
|
FileStorageHelper::removeModelFilesOfHtml($model->content);
|
||||||
|
$model->minicrudDeleted();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// * METHODS
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Apply function on data typed text while on deleted event
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function minicrudDeleted()
|
||||||
|
{
|
||||||
|
/** @var array */
|
||||||
|
foreach ($this->data as $input) {
|
||||||
|
switch ($input['inputType']) {
|
||||||
|
case InputType::text->value:
|
||||||
|
FileStorageHelper::removeModelFilesOfHtml($input['text']);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get picture_list attribute
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Support\Collection
|
||||||
|
*/
|
||||||
|
public function getPictureListAttribute(): Collection
|
||||||
|
{
|
||||||
|
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed
|
||||||
|
return \collect($this->data)->filter(fn($value, $key) => \preg_match('/bloc[0-9]+/u', $key) !== false)
|
||||||
|
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed
|
||||||
|
->groupBy(fn($value, $key) => \collect(\explode('_', $key))->take(2)->implode('_'))
|
||||||
|
->filter(fn(Collection $blocks) => \collect($blocks->first())->get('value'))
|
||||||
|
->map(function (Collection $blocks) {
|
||||||
|
$pictureBlock = (object) $blocks->last();
|
||||||
|
return (object) [
|
||||||
|
'value' => $pictureBlock->value,
|
||||||
|
'title' => $pictureBlock->title,
|
||||||
|
'alt' => $pictureBlock->alt
|
||||||
|
];
|
||||||
|
})->values();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the slug.
|
||||||
|
*
|
||||||
|
* @param self $model
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private static function setSlug(self $model)
|
||||||
|
{
|
||||||
|
$model->slug = Str::slug($model->title);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set order after the last element of the list.
|
||||||
|
*
|
||||||
|
* @param self $model
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private static function setOrder(self $model): void
|
||||||
|
{
|
||||||
|
$model->order = \intval(self::query()->max('order')) + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asserts using validation that the title is unique
|
||||||
|
*
|
||||||
|
* @param string|integer|float|boolean|null|array $title
|
||||||
|
* @param integer|null $id
|
||||||
|
* @return void
|
||||||
|
* @throws \Illuminate\Validation\ValidationException If an news title already exists.
|
||||||
|
*/
|
||||||
|
private static function assertTitleIsUnique(string|int|float|bool|null|array $title, ?int $id = null)
|
||||||
|
{
|
||||||
|
$table = (new self())->getTable();
|
||||||
|
ToolboxHelper::assertFieldIsUnique($table, 'title', $title, $id);
|
||||||
|
ToolboxHelper::assertFieldIsUnique($table, 'slug', Str::slug($title), $id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the structure necessary of data.
|
||||||
|
*
|
||||||
|
* @param string $img
|
||||||
|
* @param string $imgAlt
|
||||||
|
* @param string $imgTitle
|
||||||
|
* @return ((string|\App\Enums\InputType)[]|(string|int[]|\App\Enums\InputType)[]|(string|\App\Enums\InputType|int|(string|\Illuminate\Validation\Rules\Enum)[])[])[]
|
||||||
|
*/
|
||||||
|
public static function getEmptyData(
|
||||||
|
string $img = '',
|
||||||
|
string $imgAlt = '',
|
||||||
|
string $imgTitle = ''
|
||||||
|
) {
|
||||||
|
$data = [];
|
||||||
|
$data = self::emptyDataBloc(
|
||||||
|
'1',
|
||||||
|
$data,
|
||||||
|
$img,
|
||||||
|
$imgAlt,
|
||||||
|
$imgTitle,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
for ($i = 2; $i <= 3; $i++) {
|
||||||
|
$data = self::emptyDataBloc(
|
||||||
|
strval($i),
|
||||||
|
$data,
|
||||||
|
$img,
|
||||||
|
$imgAlt,
|
||||||
|
$imgTitle,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
} //end for
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Empty data bloc
|
||||||
|
*
|
||||||
|
* @param string $index
|
||||||
|
* @param array $data
|
||||||
|
* @param string $img
|
||||||
|
* @param string $imgAlt
|
||||||
|
* @param string $imgTitle
|
||||||
|
* @param boolean $required
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function emptyDataBloc(
|
||||||
|
string $index,
|
||||||
|
array $data,
|
||||||
|
string $img = '',
|
||||||
|
string $imgAlt = '',
|
||||||
|
string $imgTitle = '',
|
||||||
|
bool $required = false,
|
||||||
|
): array {
|
||||||
|
$data["bloc_{$index}_display_picture"] = [
|
||||||
|
'label' => "Bloc {$index} - Display picture",
|
||||||
|
'inputType' => InputType::boolean->value,
|
||||||
|
'value' => $required
|
||||||
|
];
|
||||||
|
$data["bloc_{$index}_image"] = [
|
||||||
|
'label' => "Bloc {$index} - Image",
|
||||||
|
'dimensions' => ['width' => 770, 'height' => 770],
|
||||||
|
'inputType' => InputType::image->value,
|
||||||
|
'alt' => $imgAlt,
|
||||||
|
'title' => $imgTitle,
|
||||||
|
'value' => $img,
|
||||||
|
'validate' => "required_if:data.bloc_{$index}_display_picture.value,true|nullable",
|
||||||
|
'required' => $required
|
||||||
|
];
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a SchemaOrg.
|
||||||
|
*
|
||||||
|
* @return \Spatie\SchemaOrg\NewsArticle
|
||||||
|
*/
|
||||||
|
public function toSchemaOrg(): \Spatie\SchemaOrg\NewsArticle
|
||||||
|
{
|
||||||
|
return Schema::NewsArticle()
|
||||||
|
->headline($this->seo_title)
|
||||||
|
->description($this->seo_description)
|
||||||
|
->name($this->title)
|
||||||
|
->inLanguage(config('schema-org.website.languages')[app()->currentLocale()])
|
||||||
|
->abstract($this->subtitle)
|
||||||
|
->dateCreated($this->created_at)
|
||||||
|
->dateModified($this->updated_at)
|
||||||
|
->datePublished($this->publish_at)
|
||||||
|
->articleBody(strip_tags($this->content))
|
||||||
|
->wordCount(str_word_count(strip_tags($this->content)))
|
||||||
|
->url(route('news.show', $this))
|
||||||
|
->author($this->getOrganizationSchema())
|
||||||
|
->creator($this->getOrganizationSchema())
|
||||||
|
->copyrightYear($this->created_at->year)
|
||||||
|
->image(
|
||||||
|
Schema::imageObject()
|
||||||
|
->url(asset($this->data['bloc_1_image']['value']))
|
||||||
|
->headline($this->data['bloc_1_image']['title'])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the SEO object.
|
||||||
|
*
|
||||||
|
* @return \Uwil\Seo\Laravel\Objects\SeoItem
|
||||||
|
*/
|
||||||
|
public function toSeoItem(): \Uwil\Seo\Laravel\Objects\SeoItem
|
||||||
|
{
|
||||||
|
return new SeoItem(
|
||||||
|
\trans($this->getTable()),
|
||||||
|
$this->seo_title,
|
||||||
|
$this->seo_description,
|
||||||
|
$this->status,
|
||||||
|
\route(\config('seo.bo_route_prefix') . $this->getTable() . '.edit', $this),
|
||||||
|
\route(Str::singular($this->getTable()) . '.show', $this)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To sitemap tag .
|
||||||
|
*
|
||||||
|
* @return \Spatie\Sitemap\Tags\Url|string|array
|
||||||
|
*/
|
||||||
|
public function toSitemapTag(): \Spatie\Sitemap\Tags\Url|string|array
|
||||||
|
{
|
||||||
|
return SitemapHelper::generateUrl('news.show', ['publishedNews' => $this], $this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -8,31 +8,43 @@ use App\Traits\Models\HasTranslations;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
use Uwil\Seo\Laravel\Interfaces\SeoInterface;
|
||||||
|
use Uwil\Seo\Laravel\Traits\SeoTrait;
|
||||||
|
use Spatie\SchemaOrg\Schema;
|
||||||
|
use Spatie\Sitemap\Contracts\Sitemapable;
|
||||||
|
use Uwil\SchemaOrg\Laravel\Interfaces\SchemaOrgInterface;
|
||||||
|
use Uwil\SchemaOrg\Laravel\Traits\SchemaOrgTrait;
|
||||||
|
use Uwil\Seo\Laravel\Objects\SeoItem;
|
||||||
|
use Uwil\SitemapGenerator\Lib\SitemapHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property integer $range_id
|
* @property integer $range_id
|
||||||
* @property string $seo_title
|
* @property string $seo_title
|
||||||
* @property string $seo_description
|
* @property string $seo_description
|
||||||
* @property string $label
|
* @property string $label
|
||||||
* @property string $slug
|
* @property string $slug
|
||||||
* @property string $description
|
* @property string $description
|
||||||
* @property string|null $marinade
|
* @property string|null $marinade
|
||||||
* @property string $picture
|
* @property string $picture
|
||||||
* @property array $certifications
|
* @property array $certifications
|
||||||
* @property array $nutritionnal_values
|
* @property array $nutritionnal_values
|
||||||
* @property array $list
|
* @property array $list
|
||||||
* @property boolean $status
|
* @property boolean $status
|
||||||
* @property integer $order
|
* @property integer $order
|
||||||
* @property string $created_at
|
* @property-read \Carbon\Carbon $created_at Created date.
|
||||||
* @property string $updated_at
|
* @property-read \Carbon\Carbon $updated_at Updated date.
|
||||||
*/
|
*/
|
||||||
class Product extends Model
|
class Product extends Model implements SeoInterface, SchemaOrgInterface, Sitemapable
|
||||||
{
|
{
|
||||||
use HasFactory;
|
use HasFactory;
|
||||||
use HasTranslations;
|
use HasTranslations;
|
||||||
|
use SeoTrait;
|
||||||
|
use SchemaOrgTrait;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array
|
* The attributes that are mass assignable.
|
||||||
|
*
|
||||||
|
* @var array<int, string>
|
||||||
*/
|
*/
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'range_id',
|
'range_id',
|
||||||
|
|
@ -60,7 +72,7 @@ class Product extends Model
|
||||||
/**
|
/**
|
||||||
* The attributes that should be cast.
|
* The attributes that should be cast.
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array<string, string>
|
||||||
*/
|
*/
|
||||||
protected $casts = [
|
protected $casts = [
|
||||||
'certifications' => 'array',
|
'certifications' => 'array',
|
||||||
|
|
@ -120,10 +132,10 @@ class Product extends Model
|
||||||
/**
|
/**
|
||||||
* Undocumented function
|
* Undocumented function
|
||||||
*
|
*
|
||||||
* @param Model $model
|
* @param self $model
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
private static function manageFields(Model $model)
|
private static function manageFields(self $model)
|
||||||
{
|
{
|
||||||
self::setSlug($model);
|
self::setSlug($model);
|
||||||
if (is_array($model->list)) {
|
if (is_array($model->list)) {
|
||||||
|
|
@ -143,11 +155,11 @@ class Product extends Model
|
||||||
/**
|
/**
|
||||||
* Set the slug.
|
* Set the slug.
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Database\Eloquent\Model $model
|
* @param self $model
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
private static function setSlug(Model $model)
|
private static function setSlug(self $model)
|
||||||
{
|
{
|
||||||
$model->slug = Str::slug($model->label);
|
$model->slug = Str::slug($model->label);
|
||||||
}
|
}
|
||||||
|
|
@ -169,14 +181,72 @@ class Product extends Model
|
||||||
/**
|
/**
|
||||||
* Set order after the last element of the list.
|
* Set order after the last element of the list.
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Database\Eloquent\Model $model
|
* @param self $model
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
private static function setOrder(Model $model): void
|
private static function setOrder(self $model): void
|
||||||
{
|
{
|
||||||
$model->order = \intval(self::query()->max('order')) + 1;
|
$model->order = \intval(self::query()->max('order')) + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a SchemaOrg.
|
||||||
|
*
|
||||||
|
* @return \Spatie\SchemaOrg\Product
|
||||||
|
*/
|
||||||
|
public function toSchemaOrg(): \Spatie\SchemaOrg\Product
|
||||||
|
{
|
||||||
|
$model = $this->load(['range']);
|
||||||
|
|
||||||
|
// Main.
|
||||||
|
$schema = Schema::Product()
|
||||||
|
->name($model->seo_title)
|
||||||
|
->description($model->seo_description)
|
||||||
|
->url(route('product.show', $model->slug))
|
||||||
|
->keywords('produit')
|
||||||
|
->releaseDate($model->created_at)
|
||||||
|
->image([
|
||||||
|
Schema::imageObject()
|
||||||
|
->url(asset($model->picture))
|
||||||
|
->headline($model->picture_title),
|
||||||
|
])
|
||||||
|
->brand($model->getBrandSchema());
|
||||||
|
|
||||||
|
// Range associated.
|
||||||
|
if ($model->range->status) {
|
||||||
|
$schema->subjectOf($model->range->toSchemaOrg()->toArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
return $schema;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the SEO object.
|
||||||
|
*
|
||||||
|
* @return \Uwil\Seo\Laravel\Objects\SeoItem
|
||||||
|
*/
|
||||||
|
public function toSeoItem(): \Uwil\Seo\Laravel\Objects\SeoItem
|
||||||
|
{
|
||||||
|
return new SeoItem(
|
||||||
|
\trans($this->getTable()),
|
||||||
|
$this->seo_title,
|
||||||
|
$this->seo_description,
|
||||||
|
$this->status,
|
||||||
|
\route(\config('seo.bo_route_prefix') . $this->getTable() . '.edit', $this),
|
||||||
|
\route(Str::singular($this->getTable()) . '.show', $this)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To sitemap tag .
|
||||||
|
*
|
||||||
|
* @return \Spatie\Sitemap\Tags\Url|string|array
|
||||||
|
*/
|
||||||
|
public function toSitemapTag(): \Spatie\Sitemap\Tags\Url|string|array
|
||||||
|
{
|
||||||
|
return SitemapHelper::generateUrl('product.show', ['publishedProduct' => $this], $this);
|
||||||
|
}
|
||||||
|
|
||||||
// * RELATIONSHIPS
|
// * RELATIONSHIPS
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,12 @@ use App\Traits\Models\HasTranslations;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
use Spatie\SchemaOrg\Schema;
|
||||||
|
use Uwil\SchemaOrg\Laravel\Interfaces\SchemaOrgInterface;
|
||||||
|
use Uwil\SchemaOrg\Laravel\Traits\SchemaOrgTrait;
|
||||||
|
use Uwil\Seo\Laravel\Interfaces\SeoInterface;
|
||||||
|
use Uwil\Seo\Laravel\Objects\SeoItem;
|
||||||
|
use Uwil\Seo\Laravel\Traits\SeoTrait;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property string $seo_title
|
* @property string $seo_title
|
||||||
|
|
@ -20,13 +26,17 @@ use Illuminate\Support\Str;
|
||||||
* @property string $created_at
|
* @property string $created_at
|
||||||
* @property string $updated_at
|
* @property string $updated_at
|
||||||
*/
|
*/
|
||||||
class Range extends Model
|
class Range extends Model implements SeoInterface, SchemaOrgInterface
|
||||||
{
|
{
|
||||||
use HasFactory;
|
use HasFactory;
|
||||||
use HasTranslations;
|
use HasTranslations;
|
||||||
|
use SeoTrait;
|
||||||
|
use SchemaOrgTrait;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array
|
* The attributes that are mass assignable.
|
||||||
|
*
|
||||||
|
* @var array<int, string>
|
||||||
*/
|
*/
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'seo_title',
|
'seo_title',
|
||||||
|
|
@ -43,7 +53,7 @@ class Range extends Model
|
||||||
/**
|
/**
|
||||||
* The attributes that should be cast.
|
* The attributes that should be cast.
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array<string, string>
|
||||||
*/
|
*/
|
||||||
protected $casts = [
|
protected $casts = [
|
||||||
'picto' => PictoEnum::class,
|
'picto' => PictoEnum::class,
|
||||||
|
|
@ -85,11 +95,11 @@ class Range extends Model
|
||||||
/**
|
/**
|
||||||
* Set the slug.
|
* Set the slug.
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Database\Eloquent\Model $model
|
* @param self $model
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
private static function setSlug(Model $model)
|
private static function setSlug(self $model)
|
||||||
{
|
{
|
||||||
$model->slug = Str::slug($model->label);
|
$model->slug = Str::slug($model->label);
|
||||||
}
|
}
|
||||||
|
|
@ -97,10 +107,10 @@ class Range extends Model
|
||||||
/**
|
/**
|
||||||
* Common methods function
|
* Common methods function
|
||||||
*
|
*
|
||||||
* @param Model $model
|
* @param self $model
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
private static function manageFields(Model $model)
|
private static function manageFields(self $model)
|
||||||
{
|
{
|
||||||
self::setSlug($model);
|
self::setSlug($model);
|
||||||
}
|
}
|
||||||
|
|
@ -122,14 +132,29 @@ class Range extends Model
|
||||||
/**
|
/**
|
||||||
* Set order after the last element of the list.
|
* Set order after the last element of the list.
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Database\Eloquent\Model $model
|
* @param self $model
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
private static function setOrder(Model $model): void
|
private static function setOrder(self $model): void
|
||||||
{
|
{
|
||||||
$model->order = \intval(self::query()->max('order')) + 1;
|
$model->order = \intval(self::query()->max('order')) + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a SchemaOrg.
|
||||||
|
*
|
||||||
|
* @return \Spatie\SchemaOrg\DefinedTermSet
|
||||||
|
*/
|
||||||
|
public function toSchemaOrg(): \Spatie\SchemaOrg\DefinedTermSet
|
||||||
|
{
|
||||||
|
return Schema::definedTermSet()
|
||||||
|
->hasDefinedTerm(
|
||||||
|
Schema::definedTerm()
|
||||||
|
->name($this->seo_title)
|
||||||
|
->description($this->seo_description)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// * RELATIONSHIPS
|
// * RELATIONSHIPS
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -147,4 +172,21 @@ class Range extends Model
|
||||||
{
|
{
|
||||||
return $this->hasMany('App\Models\Product');
|
return $this->hasMany('App\Models\Product');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the SEO object.
|
||||||
|
*
|
||||||
|
* @return \Uwil\Seo\Laravel\Objects\SeoItem
|
||||||
|
*/
|
||||||
|
public function toSeoItem(): \Uwil\Seo\Laravel\Objects\SeoItem
|
||||||
|
{
|
||||||
|
return new SeoItem(
|
||||||
|
\trans($this->getTable()),
|
||||||
|
$this->seo_title,
|
||||||
|
$this->seo_description,
|
||||||
|
$this->status ?? false,
|
||||||
|
\route(\config('seo.bo_route_prefix') . $this->getTable() . '.edit', $this),
|
||||||
|
'#'
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,33 +9,45 @@ use App\Traits\Models\HasTranslations;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
use Uwil\Seo\Laravel\Interfaces\SeoInterface;
|
||||||
|
use Uwil\Seo\Laravel\Traits\SeoTrait;
|
||||||
|
use Spatie\SchemaOrg\Schema;
|
||||||
|
use Spatie\Sitemap\Contracts\Sitemapable;
|
||||||
|
use Uwil\SchemaOrg\Laravel\Interfaces\SchemaOrgInterface;
|
||||||
|
use Uwil\SchemaOrg\Laravel\Traits\SchemaOrgTrait;
|
||||||
|
use Uwil\Seo\Laravel\Objects\SeoItem;
|
||||||
|
use Uwil\SitemapGenerator\Lib\SitemapHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property integer $range_id
|
* @property integer $range_id
|
||||||
* @property string $seo_title
|
* @property string $seo_title
|
||||||
* @property string $seo_description
|
* @property string $seo_description
|
||||||
* @property string $name
|
* @property string $name
|
||||||
* @property string $slug
|
* @property string $slug
|
||||||
* @property string $picture
|
* @property string $picture
|
||||||
* @property string $picture_thumbnail
|
* @property string $picture_thumbnail
|
||||||
* @property string $ingredients
|
* @property array<array<string>> $ingredients
|
||||||
* @property string $teaser
|
* @property string $teaser
|
||||||
* @property string $steps
|
* @property string $steps
|
||||||
* @property \App\Enums\Recipes\DifficultyEnum $difficulty
|
* @property \App\Enums\Recipes\DifficultyEnum $difficulty
|
||||||
* @property string $duration
|
* @property integer $duration
|
||||||
* @property string $tips
|
* @property string $tips
|
||||||
* @property boolean $status
|
* @property boolean $status
|
||||||
* @property integer $order
|
* @property integer $order
|
||||||
* @property string $created_at
|
* @property-read \Illuminate\Support\Carbon $created_at Created date.
|
||||||
* @property string $updated_at
|
* @property-read \Illuminate\Support\Carbon $updated_at Updated date.
|
||||||
*/
|
*/
|
||||||
class Recipe extends Model
|
class Recipe extends Model implements SeoInterface, SchemaOrgInterface, Sitemapable
|
||||||
{
|
{
|
||||||
use HasFactory;
|
use HasFactory;
|
||||||
use HasTranslations;
|
use HasTranslations;
|
||||||
|
use SeoTrait;
|
||||||
|
use SchemaOrgTrait;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array
|
* The attributes that are mass assignable.
|
||||||
|
*
|
||||||
|
* @var array<int, string>
|
||||||
*/
|
*/
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'range_id',
|
'range_id',
|
||||||
|
|
@ -64,11 +76,11 @@ class Recipe extends Model
|
||||||
/**
|
/**
|
||||||
* The attributes that should be cast.
|
* The attributes that should be cast.
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array<string, string>
|
||||||
*/
|
*/
|
||||||
protected $casts = [
|
protected $casts = [
|
||||||
'ingredients' => 'json',
|
'ingredients' => 'array',
|
||||||
'difficulty' => DifficultyEnum::class
|
'difficulty' => DifficultyEnum::class,
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -88,7 +100,6 @@ class Recipe extends Model
|
||||||
'picture_thumbnail_alt',
|
'picture_thumbnail_alt',
|
||||||
'picture_thumbnail_title',
|
'picture_thumbnail_title',
|
||||||
'ingredients',
|
'ingredients',
|
||||||
'duration',
|
|
||||||
'teaser',
|
'teaser',
|
||||||
'steps',
|
'steps',
|
||||||
'tips',
|
'tips',
|
||||||
|
|
@ -127,18 +138,17 @@ class Recipe extends Model
|
||||||
/**
|
/**
|
||||||
* Common methods function.
|
* Common methods function.
|
||||||
*
|
*
|
||||||
* @param Model $model
|
* @param self $model
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
private static function manageFields(Model $model)
|
private static function manageFields(self $model)
|
||||||
{
|
{
|
||||||
if (is_array($model->ingredients)) {
|
/** @var array<string,string> $itemIngredients */
|
||||||
foreach ($model->ingredients as $itemIngredients) {
|
foreach ($model->ingredients as $itemIngredients) {
|
||||||
if (isset($itemIngredients['header'])) {
|
if (isset($itemIngredients['header'])) {
|
||||||
ToolboxHelper::assertNoInternalBoUrls('ingredients', $itemIngredients['header']);
|
ToolboxHelper::assertNoInternalBoUrls('ingredients', $itemIngredients['header']);
|
||||||
}
|
|
||||||
ToolboxHelper::assertNoInternalBoUrls('ingredients', \strval($itemIngredients['value']));
|
|
||||||
}
|
}
|
||||||
|
ToolboxHelper::assertNoInternalBoUrls('ingredients', \strval($itemIngredients['value']));
|
||||||
}
|
}
|
||||||
ToolboxHelper::assertNoInternalBoUrls('steps', $model->steps);
|
ToolboxHelper::assertNoInternalBoUrls('steps', $model->steps);
|
||||||
ToolboxHelper::assertNoInternalBoUrls('tips', $model->tips);
|
ToolboxHelper::assertNoInternalBoUrls('tips', $model->tips);
|
||||||
|
|
@ -149,11 +159,11 @@ class Recipe extends Model
|
||||||
/**
|
/**
|
||||||
* Set the slug.
|
* Set the slug.
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Database\Eloquent\Model $model
|
* @param self $model
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
private static function setSlug(Model $model)
|
private static function setSlug(self $model)
|
||||||
{
|
{
|
||||||
$model->slug = Str::slug($model->name);
|
$model->slug = Str::slug($model->name);
|
||||||
}
|
}
|
||||||
|
|
@ -161,10 +171,10 @@ class Recipe extends Model
|
||||||
/**
|
/**
|
||||||
* Set order after the last element of the list.
|
* Set order after the last element of the list.
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Database\Eloquent\Model $model
|
* @param self $model
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
private static function setOrder(Model $model): void
|
private static function setOrder(self $model): void
|
||||||
{
|
{
|
||||||
$model->order = \intval(self::query()->max('order')) + 1;
|
$model->order = \intval(self::query()->max('order')) + 1;
|
||||||
}
|
}
|
||||||
|
|
@ -183,6 +193,88 @@ class Recipe extends Model
|
||||||
ToolboxHelper::assertFieldIsUnique($table, $nameField, $valueField, $id);
|
ToolboxHelper::assertFieldIsUnique($table, $nameField, $valueField, $id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create and return microdata.
|
||||||
|
*
|
||||||
|
* @return \Spatie\SchemaOrg\Recipe
|
||||||
|
*/
|
||||||
|
public function toSchemaOrg(): \Spatie\SchemaOrg\Recipe
|
||||||
|
{
|
||||||
|
$model = $this->load(['range']);
|
||||||
|
|
||||||
|
$schema = Schema::Recipe()
|
||||||
|
->name($model->seo_title)
|
||||||
|
->description($model->seo_description)
|
||||||
|
->url(route('recipe.show', $this))
|
||||||
|
->inLanguage(config('schema-org.website.languages')[app()->currentLocale()])
|
||||||
|
->keywords('recette')
|
||||||
|
->recipeCategory([
|
||||||
|
$model->difficulty->label(),
|
||||||
|
])
|
||||||
|
->recipeCuisine("Française")
|
||||||
|
->recipeInstructions(strip_tags($model->tips))
|
||||||
|
->dateCreated($model->created_at)
|
||||||
|
->dateModified($model->updated_at)
|
||||||
|
->datePublished($model->created_at)
|
||||||
|
->totalTime(
|
||||||
|
Schema::duration()->setProperty("@value", $model->formatDurationIso($model->duration))
|
||||||
|
)
|
||||||
|
->author($model->getOrganizationSchema())
|
||||||
|
->creator($model->getOrganizationSchema())
|
||||||
|
->image(
|
||||||
|
Schema::imageObject()
|
||||||
|
->url(asset($model->picture))
|
||||||
|
->headline($model->picture_title)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Steps.
|
||||||
|
preg_match_all('/<li>(.*?)<\/li>/', $model->steps, $step);
|
||||||
|
if (count($step[1])) {
|
||||||
|
$schema->steps($step[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ingredients.
|
||||||
|
$ingredientsList = [];
|
||||||
|
foreach ($model->ingredients as $ingredient) {
|
||||||
|
array_push($ingredientsList, $ingredient['value']);
|
||||||
|
};
|
||||||
|
$schema->ingredients($ingredientsList);
|
||||||
|
|
||||||
|
// Range associated.
|
||||||
|
if ($model->range->status) {
|
||||||
|
$schema->subjectOf($model->range->toSchemaOrg()->toArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
return $schema;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the SEO object.
|
||||||
|
*
|
||||||
|
* @return \Uwil\Seo\Laravel\Objects\SeoItem
|
||||||
|
*/
|
||||||
|
public function toSeoItem(): \Uwil\Seo\Laravel\Objects\SeoItem
|
||||||
|
{
|
||||||
|
return new SeoItem(
|
||||||
|
\trans($this->getTable()),
|
||||||
|
$this->seo_title,
|
||||||
|
$this->seo_description,
|
||||||
|
$this->status,
|
||||||
|
\route(\config('seo.bo_route_prefix') . $this->getTable() . '.edit', $this),
|
||||||
|
\route(Str::singular($this->getTable()) . '.show', $this)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To sitemap tag .
|
||||||
|
*
|
||||||
|
* @return \Spatie\Sitemap\Tags\Url|string|array
|
||||||
|
*/
|
||||||
|
public function toSitemapTag(): \Spatie\Sitemap\Tags\Url|string|array
|
||||||
|
{
|
||||||
|
return SitemapHelper::generateUrl('recipe.show', ['publishedRecipe' => $this], $this);
|
||||||
|
}
|
||||||
|
|
||||||
// * RELATIONSHIPS
|
// * RELATIONSHIPS
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -10,20 +10,20 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property boolean $type
|
* @property \App\Enums\Sliders\TypeEnum $type
|
||||||
* @property string $title
|
* @property string $title
|
||||||
* @property string $subtitle
|
* @property string $subtitle
|
||||||
* @property string $description
|
* @property string $description
|
||||||
* @property string $link
|
* @property string $link
|
||||||
* @property string $link_title
|
* @property string $link_title
|
||||||
* @property boolean $link_new_tab
|
* @property boolean $link_new_tab
|
||||||
* @property string $picture
|
* @property string $picture
|
||||||
* @property boolean $status
|
* @property boolean $status
|
||||||
* @property integer $order
|
* @property integer $order
|
||||||
* @property string $unpublish_at
|
* @property string|null $unpublish_at
|
||||||
* @property string $publish_at
|
* @property string|null $publish_at
|
||||||
* @property string $created_at
|
* @property \Carbon\Carbon $created_at
|
||||||
* @property string $updated_at
|
* @property \Carbon\Carbon $updated_at
|
||||||
*/
|
*/
|
||||||
class Slider extends Model
|
class Slider extends Model
|
||||||
{
|
{
|
||||||
|
|
@ -31,7 +31,9 @@ class Slider extends Model
|
||||||
use HasTranslations;
|
use HasTranslations;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array
|
* The attributes that are mass assignable.
|
||||||
|
*
|
||||||
|
* @var array<int, string>
|
||||||
*/
|
*/
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'type',
|
'type',
|
||||||
|
|
@ -46,6 +48,7 @@ class Slider extends Model
|
||||||
'picture_title',
|
'picture_title',
|
||||||
'status',
|
'status',
|
||||||
'order',
|
'order',
|
||||||
|
'locales',
|
||||||
'unpublish_at',
|
'unpublish_at',
|
||||||
'publish_at',
|
'publish_at',
|
||||||
'created_at',
|
'created_at',
|
||||||
|
|
@ -71,13 +74,14 @@ class Slider extends Model
|
||||||
/**
|
/**
|
||||||
* The attributes that should be cast.
|
* The attributes that should be cast.
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array<string, string>
|
||||||
*/
|
*/
|
||||||
protected $casts = [
|
protected $casts = [
|
||||||
'type' => TypeEnum::class,
|
'type' => TypeEnum::class,
|
||||||
'status' => 'bool',
|
'status' => 'bool',
|
||||||
'publish_at' => 'datetime',
|
'publish_at' => 'datetime',
|
||||||
'unpublish_at' => 'datetime'
|
'unpublish_at' => 'datetime',
|
||||||
|
'locales' => 'array',
|
||||||
];
|
];
|
||||||
|
|
||||||
// * EVENTS
|
// * EVENTS
|
||||||
|
|
@ -115,10 +119,10 @@ class Slider extends Model
|
||||||
/**
|
/**
|
||||||
* Common methods function.
|
* Common methods function.
|
||||||
*
|
*
|
||||||
* @param Model $model
|
* @param self $model
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
private static function manageFields(Model $model)
|
private static function manageFields(self $model)
|
||||||
{
|
{
|
||||||
if ($model->link) {
|
if ($model->link) {
|
||||||
ToolboxHelper::assertNoInternalBoUrls('link', $model->link);
|
ToolboxHelper::assertNoInternalBoUrls('link', $model->link);
|
||||||
|
|
@ -130,10 +134,10 @@ class Slider extends Model
|
||||||
/**
|
/**
|
||||||
* Set order after the last element of the list.
|
* Set order after the last element of the list.
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Database\Eloquent\Model $model
|
* @param self $model
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
private static function setOrder(Model $model): void
|
private static function setOrder(self $model): void
|
||||||
{
|
{
|
||||||
$model->order = \intval(self::query()->max('order')) + 1;
|
$model->order = \intval(self::query()->max('order')) + 1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
172
app/Models/StaticPage.php
Normal file
172
app/Models/StaticPage.php
Normal file
|
|
@ -0,0 +1,172 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use App\Enums\StaticPageType;
|
||||||
|
use App\Lib\Helpers\ToolboxHelper;
|
||||||
|
use App\Traits\Models\HasTranslations;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
use Spatie\SchemaOrg\Schema;
|
||||||
|
use Uwil\SchemaOrg\Laravel\Interfaces\SchemaOrgInterface;
|
||||||
|
use Uwil\SchemaOrg\Laravel\Traits\SchemaOrgTrait;
|
||||||
|
use Uwil\Seo\Laravel\Interfaces\SeoInterface;
|
||||||
|
use Uwil\Seo\Laravel\Objects\SeoItem;
|
||||||
|
use Uwil\Seo\Laravel\Traits\SeoTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property \App\Enums\StaticPageType $type Page type (StaticPageEnum).
|
||||||
|
* @property string $seo_title Seo title about 70 chars as recommended.
|
||||||
|
* @property string $seo_description Seo description about 160 chars as recommended.
|
||||||
|
* @property string $title Title for the page.
|
||||||
|
* @property string $slug Slug of the title for the page.
|
||||||
|
* @property string $content WYSIWYG text content using ckeditor.
|
||||||
|
* @property-read \Illuminate\Support\Carbon $created_at Created date.
|
||||||
|
* @property-read \Illuminate\Support\Carbon $updated_at Updated date.
|
||||||
|
*/
|
||||||
|
class StaticPage extends Model implements SeoInterface, SchemaOrgInterface
|
||||||
|
{
|
||||||
|
use HasFactory;
|
||||||
|
use HasTranslations;
|
||||||
|
use SeoTrait;
|
||||||
|
use SchemaOrgTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The attributes that are mass assignable.
|
||||||
|
*
|
||||||
|
* @var array<int, string>
|
||||||
|
*/
|
||||||
|
protected $fillable = [
|
||||||
|
'seo_title',
|
||||||
|
'seo_description',
|
||||||
|
'title',
|
||||||
|
'content',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The translatable columns.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
public $translatable = [
|
||||||
|
'seo_title',
|
||||||
|
'seo_description',
|
||||||
|
'title',
|
||||||
|
'slug',
|
||||||
|
'content',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The attributes that should be cast.
|
||||||
|
*
|
||||||
|
* @var array<string, string>
|
||||||
|
*/
|
||||||
|
protected $casts = [
|
||||||
|
'type' => StaticPageType::class,
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Perform any actions required after the model boots.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected static function booted(): void
|
||||||
|
{
|
||||||
|
static::creating(function (self $model) {
|
||||||
|
// * ASSERTIONS
|
||||||
|
self::assertTitleIsUnique($model->title);
|
||||||
|
|
||||||
|
// * CHANGES
|
||||||
|
$model->slug = Str::slug($model->title);
|
||||||
|
});
|
||||||
|
static::updating(function (self $model) {
|
||||||
|
// * ASSERTIONS
|
||||||
|
self::assertTitleIsUnique($model->title, $model->id);
|
||||||
|
|
||||||
|
// * CHANGES
|
||||||
|
$model->slug = Str::slug($model->title);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// * ROUTABLE
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the value of the model's route key.
|
||||||
|
*
|
||||||
|
* @return string|integer
|
||||||
|
*/
|
||||||
|
public function getRouteKey(): string|int
|
||||||
|
{
|
||||||
|
/** @var \App\Enums\StaticPageType */
|
||||||
|
$enum = $this->getAttribute($this->getRouteKeyName());
|
||||||
|
return $enum->value();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the route key for the model.
|
||||||
|
*
|
||||||
|
* ! Type is the routable parameter
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getRouteKeyName(): string
|
||||||
|
{
|
||||||
|
return 'type';
|
||||||
|
}
|
||||||
|
|
||||||
|
// * METHODS
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asserts using validation that the title is unique
|
||||||
|
*
|
||||||
|
* @param string|null $title
|
||||||
|
* @param integer|null $id
|
||||||
|
* @return void
|
||||||
|
* @throws \Illuminate\Validation\ValidationException If an actu title already exists.
|
||||||
|
*/
|
||||||
|
private static function assertTitleIsUnique(string|null $title, ?int $id = null): void
|
||||||
|
{
|
||||||
|
$table = (new self())->getTable();
|
||||||
|
ToolboxHelper::assertFieldIsUnique($table, 'title', $title, $id);
|
||||||
|
ToolboxHelper::assertFieldIsUnique($table, 'slug', Str::slug($title), $id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a SchemaOrg.
|
||||||
|
*
|
||||||
|
* @return \Spatie\SchemaOrg\WebPage
|
||||||
|
*/
|
||||||
|
public function toSchemaOrg(): \Spatie\SchemaOrg\WebPage
|
||||||
|
{
|
||||||
|
return Schema::webPage()
|
||||||
|
->name($this->seo_title)
|
||||||
|
->description($this->seo_description)
|
||||||
|
->headline($this->title)
|
||||||
|
->isAccessibleForFree(true)
|
||||||
|
->keywords(['page'])
|
||||||
|
->dateCreated($this->created_at)
|
||||||
|
->dateModified($this->updated_at)
|
||||||
|
->reviewedBy($this->getOrganizationSchema())
|
||||||
|
->publisher($this->getOrganizationSchema())
|
||||||
|
->author($this->getOrganizationSchema())
|
||||||
|
->isPartOf($this->getWebsiteSchema());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the SEO object.
|
||||||
|
*
|
||||||
|
* @return \Uwil\Seo\Laravel\Objects\SeoItem
|
||||||
|
*/
|
||||||
|
public function toSeoItem(): \Uwil\Seo\Laravel\Objects\SeoItem
|
||||||
|
{
|
||||||
|
return new SeoItem(
|
||||||
|
\trans($this->getTable()),
|
||||||
|
$this->seo_title,
|
||||||
|
$this->seo_description,
|
||||||
|
true,
|
||||||
|
route('bo.static_pages.edit', $this),
|
||||||
|
'#',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -23,7 +23,9 @@ class Store extends Model
|
||||||
use HasFactory;
|
use HasFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array
|
* The attributes that are mass assignable.
|
||||||
|
*
|
||||||
|
* @var array<int, string>
|
||||||
*/
|
*/
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'type_id',
|
'type_id',
|
||||||
|
|
@ -42,7 +44,7 @@ class Store extends Model
|
||||||
/**
|
/**
|
||||||
* The attributes that should be cast.
|
* The attributes that should be cast.
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array<string, string>
|
||||||
*/
|
*/
|
||||||
protected $casts = [
|
protected $casts = [
|
||||||
'latitude' => 'float',
|
'latitude' => 'float',
|
||||||
|
|
@ -68,10 +70,10 @@ class Store extends Model
|
||||||
/**
|
/**
|
||||||
* Set order after the last element of the list.
|
* Set order after the last element of the list.
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Database\Eloquent\Model $model
|
* @param self $model
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
private static function setOrder(Model $model): void
|
private static function setOrder(self $model): void
|
||||||
{
|
{
|
||||||
$model->order = \intval(self::query()->max('order')) + 1;
|
$model->order = \intval(self::query()->max('order')) + 1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,9 @@ class StoreGroup extends Model
|
||||||
use HasFactory;
|
use HasFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array
|
* The attributes that are mass assignable.
|
||||||
|
*
|
||||||
|
* @var array<int, string>
|
||||||
*/
|
*/
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'name',
|
'name',
|
||||||
|
|
@ -59,10 +61,10 @@ class StoreGroup extends Model
|
||||||
/**
|
/**
|
||||||
* Undocumented function
|
* Undocumented function
|
||||||
*
|
*
|
||||||
* @param Model $model
|
* @param self $model
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
private static function manageFields(Model $model)
|
private static function manageFields(self $model)
|
||||||
{
|
{
|
||||||
$model->picture = FileStorageHelper::storeFile($model, $model->picture, true);
|
$model->picture = FileStorageHelper::storeFile($model, $model->picture, true);
|
||||||
}
|
}
|
||||||
|
|
@ -70,10 +72,10 @@ class StoreGroup extends Model
|
||||||
/**
|
/**
|
||||||
* Set order after the last element of the list.
|
* Set order after the last element of the list.
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Database\Eloquent\Model $model
|
* @param self $model
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
private static function setOrder(Model $model): void
|
private static function setOrder(self $model): void
|
||||||
{
|
{
|
||||||
$model->order = \intval(self::query()->max('order')) + 1;
|
$model->order = \intval(self::query()->max('order')) + 1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,14 +20,17 @@ class StoreRegion extends Model
|
||||||
use HasFactory;
|
use HasFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array
|
* The attributes that are mass assignable.
|
||||||
|
*
|
||||||
|
* @var array<int, string>
|
||||||
*/
|
*/
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'group_id',
|
'group_id',
|
||||||
'name',
|
'name',
|
||||||
'picture',
|
'picture',
|
||||||
|
'order',
|
||||||
'created_at',
|
'created_at',
|
||||||
'updated_at'
|
'updated_at',
|
||||||
];
|
];
|
||||||
|
|
||||||
// * EVENTS
|
// * EVENTS
|
||||||
|
|
@ -60,10 +63,10 @@ class StoreRegion extends Model
|
||||||
/**
|
/**
|
||||||
* Undocumented function
|
* Undocumented function
|
||||||
*
|
*
|
||||||
* @param Model $model
|
* @param self $model
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
private static function manageFields(Model $model)
|
private static function manageFields(self $model)
|
||||||
{
|
{
|
||||||
$model->picture = FileStorageHelper::storeFile($model, $model->picture, true);
|
$model->picture = FileStorageHelper::storeFile($model, $model->picture, true);
|
||||||
}
|
}
|
||||||
|
|
@ -71,10 +74,10 @@ class StoreRegion extends Model
|
||||||
/**
|
/**
|
||||||
* Set order after the last element of the list.
|
* Set order after the last element of the list.
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Database\Eloquent\Model $model
|
* @param self $model
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
private static function setOrder(Model $model): void
|
private static function setOrder(self $model): void
|
||||||
{
|
{
|
||||||
$model->order = \intval(self::query()->max('order')) + 1;
|
$model->order = \intval(self::query()->max('order')) + 1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,12 +16,15 @@ class StoreType extends Model
|
||||||
use HasFactory;
|
use HasFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array
|
* The attributes that are mass assignable.
|
||||||
|
*
|
||||||
|
* @var array<int, string>
|
||||||
*/
|
*/
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'name',
|
'name',
|
||||||
|
'order',
|
||||||
'created_at',
|
'created_at',
|
||||||
'updated_at'
|
'updated_at',
|
||||||
];
|
];
|
||||||
|
|
||||||
// * EVENTS
|
// * EVENTS
|
||||||
|
|
@ -58,10 +61,10 @@ class StoreType extends Model
|
||||||
/**
|
/**
|
||||||
* Set order after the last element of the list.
|
* Set order after the last element of the list.
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Database\Eloquent\Model $model
|
* @param self $model
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
private static function setOrder(Model $model): void
|
private static function setOrder(self $model): void
|
||||||
{
|
{
|
||||||
$model->order = \intval(self::query()->max('order')) + 1;
|
$model->order = \intval(self::query()->max('order')) + 1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
36
app/Policies/StaticPagePolicy.php
Normal file
36
app/Policies/StaticPagePolicy.php
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Policies;
|
||||||
|
|
||||||
|
use App\Models\StaticPage;
|
||||||
|
use App\Models\User;
|
||||||
|
|
||||||
|
class StaticPagePolicy
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine whether the user can view any models.
|
||||||
|
*
|
||||||
|
* @param \App\Models\User $authUser
|
||||||
|
* @return boolean
|
||||||
|
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.Found
|
||||||
|
*/
|
||||||
|
public function viewAny(User $authUser): bool
|
||||||
|
{
|
||||||
|
// phpcs:enable
|
||||||
|
return auth('backend')->check();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can update the model.
|
||||||
|
*
|
||||||
|
* @param \App\Models\User $authUser
|
||||||
|
* @param \App\Models\StaticPage $static_page
|
||||||
|
* @return boolean
|
||||||
|
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
|
||||||
|
*/
|
||||||
|
public function update(User $authUser, StaticPage $static_page): bool
|
||||||
|
{
|
||||||
|
// phpcs:enable
|
||||||
|
return auth('backend')->check();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -4,6 +4,7 @@ namespace App\Providers;
|
||||||
|
|
||||||
use App\Lib\Helpers\ToolboxHelper;
|
use App\Lib\Helpers\ToolboxHelper;
|
||||||
use App\Models\Concept;
|
use App\Models\Concept;
|
||||||
|
use App\Models\News;
|
||||||
use App\Models\Product;
|
use App\Models\Product;
|
||||||
use App\Models\Range;
|
use App\Models\Range;
|
||||||
use App\Models\Recipe;
|
use App\Models\Recipe;
|
||||||
|
|
@ -18,6 +19,7 @@ use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvi
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\RateLimiter;
|
use Illuminate\Support\Facades\RateLimiter;
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
class RouteServiceProvider extends ServiceProvider
|
class RouteServiceProvider extends ServiceProvider
|
||||||
{
|
{
|
||||||
|
|
@ -55,27 +57,40 @@ class RouteServiceProvider extends ServiceProvider
|
||||||
|
|
||||||
Route::bind('publishedRecipe', function ($value) use ($defaultLocale) {
|
Route::bind('publishedRecipe', function ($value) use ($defaultLocale) {
|
||||||
$query = Recipe::query()
|
$query = Recipe::query()
|
||||||
->whereHas('range', fn (Builder $q) => $q->where('status', true))
|
->whereHas('range', fn(Builder $q) => $q->where('status', true))
|
||||||
->where('status', true);
|
->where('status', true);
|
||||||
return ToolboxHelper::queryColumnWithLocales(
|
return ToolboxHelper::queryColumnWithLocales(
|
||||||
$defaultLocale,
|
$defaultLocale,
|
||||||
$query,
|
$query,
|
||||||
'slug',
|
'slug',
|
||||||
$value
|
Str::slug(urldecode($value))
|
||||||
)->firstOrFail();
|
)->firstOrFail();
|
||||||
});
|
});
|
||||||
Route::bind('publishedProduct', function ($value) use ($defaultLocale) {
|
Route::bind('publishedProduct', function ($value) use ($defaultLocale) {
|
||||||
$query = Product::query()
|
$query = Product::query()
|
||||||
->whereHas('range', fn (Builder $q) => $q->where('status', true))
|
->whereHas('range', fn(Builder $q) => $q->where('status', true))
|
||||||
->where('status', true);
|
->where('status', true);
|
||||||
return ToolboxHelper::queryColumnWithLocales(
|
return ToolboxHelper::queryColumnWithLocales(
|
||||||
$defaultLocale,
|
$defaultLocale,
|
||||||
$query,
|
$query,
|
||||||
'slug',
|
'slug',
|
||||||
$value
|
Str::slug(urldecode($value))
|
||||||
|
)->firstOrFail();
|
||||||
|
});
|
||||||
|
Route::bind('publishedNews', function ($value) use ($defaultLocale) {
|
||||||
|
$currentLocale = app()->currentLocale();
|
||||||
|
$query = News::query()
|
||||||
|
->whereJsonContains('locales', $currentLocale)
|
||||||
|
->where('status', true);
|
||||||
|
return ToolboxHelper::queryColumnWithLocales(
|
||||||
|
$defaultLocale,
|
||||||
|
$query,
|
||||||
|
'slug',
|
||||||
|
Str::slug(urldecode($value))
|
||||||
)->firstOrFail();
|
)->firstOrFail();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Route::model('news', News::class);
|
||||||
Route::model('concept', Concept::class);
|
Route::model('concept', Concept::class);
|
||||||
Route::model('range', Range::class);
|
Route::model('range', Range::class);
|
||||||
Route::model('product', Product::class);
|
Route::model('product', Product::class);
|
||||||
|
|
@ -123,13 +138,16 @@ class RouteServiceProvider extends ServiceProvider
|
||||||
}
|
}
|
||||||
// * Flatten if needed
|
// * Flatten if needed
|
||||||
$cspReport = collect(request()->json('csp-report'))
|
$cspReport = collect(request()->json('csp-report'))
|
||||||
->flatMap(function ($v, $k) {
|
->flatMap(function ($v, $k) {
|
||||||
return [$k => is_array($v) ? collect($v)->flatten()->implode(', ') : $v];
|
return [$k => is_array($v) ? collect($v)->flatten()->implode(', ') : $v];
|
||||||
})->all();
|
})->all();
|
||||||
// * Filter array keys
|
// * Filter array keys
|
||||||
$cspReport = collect(array_intersect_key($cspReport, [
|
$cspReport = collect(array_intersect_key($cspReport, [
|
||||||
'blocked-uri' => '', 'document-uri' => '', 'original-policy' => '',
|
'blocked-uri' => '',
|
||||||
'referrer' => '', 'violated-directive' => ''
|
'document-uri' => '',
|
||||||
|
'original-policy' => '',
|
||||||
|
'referrer' => '',
|
||||||
|
'violated-directive' => ''
|
||||||
]));
|
]));
|
||||||
\Illuminate\Support\Facades\Log::warning(sprintf(
|
\Illuminate\Support\Facades\Log::warning(sprintf(
|
||||||
"CSP REPORT for %s : \n %s",
|
"CSP REPORT for %s : \n %s",
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ class TranslationServiceProvider extends ServiceProvider
|
||||||
/**
|
/**
|
||||||
* Gather provided langs checking from files
|
* Gather provided langs checking from files
|
||||||
*
|
*
|
||||||
* @return \Illuminate\Support\Collection<string, string>
|
* @return \Illuminate\Support\Collection<int, string>
|
||||||
*/
|
*/
|
||||||
private function collectLocalesStrings(): Collection
|
private function collectLocalesStrings(): Collection
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -3,59 +3,56 @@
|
||||||
namespace App\Traits\Controllers;
|
namespace App\Traits\Controllers;
|
||||||
|
|
||||||
use App\Http\Requests\Bo\ChangeOrderRequest;
|
use App\Http\Requests\Bo\ChangeOrderRequest;
|
||||||
use App\Traits\Models\IsCachedAsCollection;
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Http\RedirectResponse;
|
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Facades\Session;
|
use Illuminate\Support\Facades\Session;
|
||||||
use Illuminate\Validation\ValidationException;
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
trait ChangesModelOrder
|
trait ChangesModelOrder
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Change order
|
* Change order.
|
||||||
*
|
|
||||||
* ! requires x64 server + order column as unique integer
|
|
||||||
*
|
*
|
||||||
* @param \App\Http\Requests\Bo\ChangeOrderRequest $request
|
* @param \App\Http\Requests\Bo\ChangeOrderRequest $request
|
||||||
* @param \Illuminate\Database\Eloquent\Model $model
|
* @param \Illuminate\Database\Eloquent\Model $model
|
||||||
* @return \Illuminate\Http\RedirectResponse
|
* @return \Illuminate\Http\RedirectResponse
|
||||||
* @throws \RuntimeException Si le nom du parametre de la route ne correspond pas au model utilisé.
|
* @throws \RuntimeException Si le nom du parametre de la route ne correspond pas au model utilisé.
|
||||||
*/
|
*/
|
||||||
public function changeOrder(ChangeOrderRequest $request, Model $model): RedirectResponse
|
public function changeOrder(ChangeOrderRequest $request, Model $model): \Illuminate\Http\RedirectResponse
|
||||||
{
|
{
|
||||||
return DB::transaction(function () use ($request, $model) {
|
$params = collect(request()->route()->parameterNames);
|
||||||
|
$className = Str::ucfirst(Str::lower($params->get($params->count() - 2)));
|
||||||
|
$className = "\\App\\Models\\$className";
|
||||||
|
|
||||||
|
if (!class_exists($className)) {
|
||||||
|
throw new \RuntimeException("The $className class doesn't exist.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var \Illuminate\Database\Eloquent\Model|null */
|
||||||
|
$model = $className::query()->where($model->getRouteKeyName(), $model->getRouteKey())->first();
|
||||||
|
|
||||||
|
if (!$model) {
|
||||||
|
return back()->with('error', trans('crud.messages.order_not_changed'));
|
||||||
|
}
|
||||||
|
|
||||||
|
return DB::transaction(function () use ($request, $className, $model) {
|
||||||
/** @var \Illuminate\Database\Eloquent\Model|null */
|
/** @var \Illuminate\Database\Eloquent\Model|null */
|
||||||
$tmp = (\get_class($model))::where('order', $request->direction ? '<' : '>', $model->order)
|
$tmp = $className::query()->where('order', $request->direction ? '<' : '>', $model->getOriginal('order'))
|
||||||
->orderBy('order', $request->direction ? 'DESC' : 'ASC')->first();
|
->orderBy('order', $request->direction ? 'DESC' : 'ASC')->first();
|
||||||
|
|
||||||
if (!$tmp) {
|
if (!$tmp) {
|
||||||
return back()->with('bo.error', trans('L\'ordre n\'a pas pu être modifié'));
|
return back()->with('error', trans('crud.messages.order_not_changed'));
|
||||||
}
|
}
|
||||||
$oldOrder = $model->order;
|
|
||||||
$newOrder = $tmp->order;
|
|
||||||
|
|
||||||
// * Silent update timestamps.
|
$newOrder = $tmp->getOriginal('order');
|
||||||
$tmp->timestamps = false;
|
// Didn't use ->update() because it didn't work with Models which use MiniCrudModel.
|
||||||
$model->timestamps = false;
|
$tmp->fill(['order' => $model->getOriginal('order')]);
|
||||||
|
$tmp->save();
|
||||||
|
$model->fill(['order' => $newOrder]);
|
||||||
|
$model->save();
|
||||||
|
|
||||||
$saveOk = false;
|
Session::flash('success', trans('crud.messages.order_changed'));
|
||||||
|
|
||||||
// ! Fake value to prevent unique SQL key to trigger.
|
|
||||||
$tmp->order = 4294967295;
|
|
||||||
$saveOk = $tmp->saveQuietly();
|
|
||||||
$model->order = $newOrder;
|
|
||||||
$saveOk = $model->saveQuietly() & $saveOk;
|
|
||||||
$tmp->order = $oldOrder;
|
|
||||||
$saveOk = $tmp->saveQuietly() & $saveOk;
|
|
||||||
if (\in_array(IsCachedAsCollection::class, class_uses_recursive(\get_class($model)))) {
|
|
||||||
$model::removeCached();
|
|
||||||
}
|
|
||||||
if (!$saveOk) {
|
|
||||||
throw ValidationException::withMessages([
|
|
||||||
'error' => \trans('L\'ordre n\'a pas pu être modifié')
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
Session::flash('bo.success', trans('L\'ordre a été modifié'));
|
|
||||||
return back();
|
return back();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,9 @@
|
||||||
|
|
||||||
namespace App\Traits\Controllers;
|
namespace App\Traits\Controllers;
|
||||||
|
|
||||||
|
use App\Interfaces\Models\Publishable;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use App\Traits\Models\IsPublishable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This trait works with Route::bind in App service provider
|
* This trait works with Route::bind in App service provider
|
||||||
|
|
@ -12,19 +14,54 @@ use Illuminate\Database\Eloquent\Model;
|
||||||
trait UpdateModelStatus
|
trait UpdateModelStatus
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Change model published
|
* Change model published boolean
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Database\Eloquent\Model $model
|
* @param \Illuminate\Database\Eloquent\Model $model
|
||||||
* @return \Illuminate\Http\RedirectResponse
|
* @return \Illuminate\Http\RedirectResponse
|
||||||
*/
|
*/
|
||||||
public function changePublished(Model $model)
|
public function changePublished(Model $model)
|
||||||
{
|
{
|
||||||
$model->status = !$model->status;
|
$model->update(['status' => !$model->getOriginal('status')]);
|
||||||
$model->saveOrFail();
|
|
||||||
|
|
||||||
if (!$model->saveOrFail()) {
|
|
||||||
return redirect()->back()->with('error', __('The status could not be changed'));
|
|
||||||
}
|
|
||||||
return redirect()->back()->with('success', __('The status has been changed'));
|
return redirect()->back()->with('success', __('The status has been changed'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Change model publication date + boolean
|
||||||
|
*
|
||||||
|
* @param Model $model
|
||||||
|
* @return \Illuminate\Http\RedirectResponse
|
||||||
|
* @throws \InvalidArgumentException Model must use IsPublishable trait.
|
||||||
|
*/
|
||||||
|
public function updatePublicationDate(Model $model)
|
||||||
|
{
|
||||||
|
if (!$this->isPublishable($model)) {
|
||||||
|
throw new \InvalidArgumentException('Model must use IsPublishable trait');
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var Publishable&Model $model */
|
||||||
|
if ($model->getStatus()) {
|
||||||
|
$model->setUnpublishAt(now());
|
||||||
|
$model->setStatus(false);
|
||||||
|
} else {
|
||||||
|
$model->setPublishAt(now());
|
||||||
|
$model->setUnpublishAt(null);
|
||||||
|
$model->setStatus(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
$model->saveOrFail();
|
||||||
|
return redirect()->back()->with('success', __('The status has been changed'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a Model implements Publishable interface.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Database\Eloquent\Model $model
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
protected function isPublishable(Model $model): bool
|
||||||
|
{
|
||||||
|
return $model instanceof Publishable &&
|
||||||
|
in_array(IsPublishable::class, class_uses_recursive($model));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,14 +4,12 @@ namespace App\Traits\Enums;
|
||||||
|
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Jérémy Munsch <jeremy.munsch@ldc.fr>
|
|
||||||
*/
|
|
||||||
trait BaseEnum
|
trait BaseEnum
|
||||||
{
|
{
|
||||||
// * GENERIC METHODS
|
// * GENERIC METHODS
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get enum value
|
* Get enum value.
|
||||||
*
|
*
|
||||||
* @return string|integer
|
* @return string|integer
|
||||||
*/
|
*/
|
||||||
|
|
@ -21,7 +19,7 @@ trait BaseEnum
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get enum label
|
* Get enum label.
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
|
|
@ -31,7 +29,7 @@ trait BaseEnum
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get enum name
|
* Get enum name.
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
|
|
@ -43,7 +41,7 @@ trait BaseEnum
|
||||||
// * STATIC FETCH METHODS
|
// * STATIC FETCH METHODS
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get enum labels
|
* Get enum labels.
|
||||||
*
|
*
|
||||||
* @return array<string>
|
* @return array<string>
|
||||||
*/
|
*/
|
||||||
|
|
@ -65,7 +63,7 @@ trait BaseEnum
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get enum values
|
* Get enum values.
|
||||||
*
|
*
|
||||||
* @return array<integer|string>
|
* @return array<integer|string>
|
||||||
*/
|
*/
|
||||||
|
|
@ -79,7 +77,7 @@ trait BaseEnum
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get enums
|
* Get enums.
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
|
|
@ -89,7 +87,7 @@ trait BaseEnum
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get enums
|
* Get enums.
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
|
|
@ -111,37 +109,43 @@ trait BaseEnum
|
||||||
}
|
}
|
||||||
$baseArray[$index] = $elements[$enum->name];
|
$baseArray[$index] = $elements[$enum->name];
|
||||||
}
|
}
|
||||||
return [$enum->name => (object)$baseArray];
|
return [$enum->name => (object) $baseArray];
|
||||||
})->all());
|
})->all());
|
||||||
}
|
}
|
||||||
return self::getCache('enums');
|
return self::getCache('enums');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch enum using value
|
* Fetch enum using value.
|
||||||
*
|
*
|
||||||
* @param \App\Traits\Enums\BaseEnum|integer|string $value
|
* @param self|integer|string $value
|
||||||
* @return \App\Traits\Enums\BaseEnum|null
|
* @param string $field
|
||||||
|
* @return self|null
|
||||||
*/
|
*/
|
||||||
public static function make(self|int|string $value): self|null
|
public static function make(self|int|string $value, string $field = 'value'): self|null
|
||||||
{
|
{
|
||||||
|
if ($field === "label") {
|
||||||
|
$enumLabels = array_change_key_case(array_flip(self::toLabels()), CASE_LOWER);
|
||||||
|
$value = (isset($enumLabels[strtolower($value)])) ? $enumLabels[strtolower($value)] : false;
|
||||||
|
$field = 'name';
|
||||||
|
}
|
||||||
return !\is_object($value) ?
|
return !\is_object($value) ?
|
||||||
\collect(self::cases())->keyBy('value')->get($value) : $value;
|
\collect(self::cases())->keyBy($field)->get($value) : $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test if 2 enum are equals
|
* Test if 2 enum are equals.
|
||||||
*
|
*
|
||||||
* @param object ...$others
|
* @param object ...$others
|
||||||
* @return boolean
|
* @return boolean
|
||||||
* @throws \Error If provided element are not enums taht extends BaseEnum.
|
* @throws \Error If provided element are not enums that extends BaseEnum.
|
||||||
*/
|
*/
|
||||||
public function equals(object ...$others): bool
|
public function equals(object ...$others): bool
|
||||||
{
|
{
|
||||||
foreach ($others as $other) {
|
foreach ($others as $other) {
|
||||||
if (!\in_array(BaseEnum::class, \class_uses_recursive($other))) {
|
if (!\in_array(BaseEnum::class, \class_uses_recursive($other))) {
|
||||||
throw new \Error(__METHOD__ .
|
throw new \Error(__METHOD__ .
|
||||||
' requires $enum to use ' . BaseEnum::class);
|
' requires $enum to use ' . BaseEnum::class);
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
get_class($this) === get_class($other)
|
get_class($this) === get_class($other)
|
||||||
|
|
@ -154,7 +158,7 @@ trait BaseEnum
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Serialize to json
|
* Serialize to json.
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
|
|
@ -167,7 +171,7 @@ trait BaseEnum
|
||||||
// * CACHE
|
// * CACHE
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get cache array
|
* Get cache array.
|
||||||
*
|
*
|
||||||
* @param string $index
|
* @param string $index
|
||||||
* @return array
|
* @return array
|
||||||
|
|
@ -182,7 +186,7 @@ trait BaseEnum
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set cache array
|
* Set cache array.
|
||||||
*
|
*
|
||||||
* @param string $index
|
* @param string $index
|
||||||
* @param array $items
|
* @param array $items
|
||||||
|
|
@ -198,7 +202,7 @@ trait BaseEnum
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Init cache if needed
|
* Init cache if needed.
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
|
|
@ -219,7 +223,7 @@ trait BaseEnum
|
||||||
// * PRIVATE
|
// * PRIVATE
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch the LABELS constant if exists
|
* Fetch the LABELS constant if exists.
|
||||||
*
|
*
|
||||||
* @return array|null
|
* @return array|null
|
||||||
*/
|
*/
|
||||||
|
|
@ -235,7 +239,7 @@ trait BaseEnum
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get custom constants
|
* Get custom constants.
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -36,9 +36,13 @@ trait HasTranslations
|
||||||
|
|
||||||
// * Store Uploaded file
|
// * Store Uploaded file
|
||||||
if (\is_object($value) and $value instanceof \Illuminate\Http\UploadedFile) {
|
if (\is_object($value) and $value instanceof \Illuminate\Http\UploadedFile) {
|
||||||
$storeAsPrivate = (\is_array($this->privatePictures) and
|
if (\property_exists($this, 'privatePictures')) {
|
||||||
\in_array($key, $this->privatePictures)) ? true : false;
|
$storeAsPrivate = (\is_array($this->privatePictures) and
|
||||||
$value = FileStorageHelper::storeFile($this, $value, true, null, $storeAsPrivate);
|
\in_array($key, $this->privatePictures)) ? true : false;
|
||||||
|
} else {
|
||||||
|
$storeAsPrivate = false;
|
||||||
|
}
|
||||||
|
$value = FileStorageHelper::storeFile($this, $value, true, null, $storeAsPrivate);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the attribute is translatable and not already translated, set a
|
// If the attribute is translatable and not already translated, set a
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,8 @@ use Illuminate\Support\Facades\Cache;
|
||||||
/**
|
/**
|
||||||
* ! Use this only on limited elements, (not on tags, or products, or posts for ex.)
|
* ! Use this only on limited elements, (not on tags, or products, or posts for ex.)
|
||||||
*
|
*
|
||||||
* @property private static array $cacheConditions Eloquent condition to cache elements (to be used in where statement).
|
* @property array<string,string|integer|float|boolean> $cacheConditions
|
||||||
|
* Eloquent condition to cache elements (to be used in where statement).
|
||||||
*/
|
*/
|
||||||
trait IsCachedAsCollection
|
trait IsCachedAsCollection
|
||||||
{
|
{
|
||||||
|
|
@ -18,7 +19,7 @@ trait IsCachedAsCollection
|
||||||
* Get all available instances from cache.
|
* Get all available instances from cache.
|
||||||
* If cache was reset, it will fetch them from DB.
|
* If cache was reset, it will fetch them from DB.
|
||||||
*
|
*
|
||||||
* @return \Illuminate\Database\Eloquent\Collection
|
* @return \Illuminate\Database\Eloquent\Collection|\Illuminate\Support\Collection<(int|string), mixed>
|
||||||
*/
|
*/
|
||||||
public static function getCached(): Collection
|
public static function getCached(): Collection
|
||||||
{
|
{
|
||||||
|
|
@ -52,10 +53,11 @@ trait IsCachedAsCollection
|
||||||
{
|
{
|
||||||
$conditions = [];
|
$conditions = [];
|
||||||
if (property_exists(get_called_class(), 'cacheConditions')) {
|
if (property_exists(get_called_class(), 'cacheConditions')) {
|
||||||
$conditions = collect(static::${'cacheConditions'})->all();
|
$conditions = collect(get_called_class()::${'cacheConditions'})->all();
|
||||||
}
|
}
|
||||||
Cache::put(static::getCacheKeyName(), static::queryCached(static::query())
|
Cache::put(static::getCacheKeyName(), static::queryCached(static::query())
|
||||||
->where($conditions)->get());
|
->where($conditions)->get()
|
||||||
|
->pipe(fn (Collection $collection) => \call_user_func([self::class, 'filterQuery'], $collection)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -69,6 +71,17 @@ trait IsCachedAsCollection
|
||||||
return $query;
|
return $query;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Change query for cached elements
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Support\Collection $results
|
||||||
|
* @return \Illuminate\Support\Collection
|
||||||
|
*/
|
||||||
|
protected static function filterQuery(Collection $results): Collection
|
||||||
|
{
|
||||||
|
return $results;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the class basename
|
* Get the class basename
|
||||||
*
|
*
|
||||||
|
|
|
||||||
140
app/Traits/Models/IsPublishable.php
Normal file
140
app/Traits/Models/IsPublishable.php
Normal file
|
|
@ -0,0 +1,140 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Traits\Models;
|
||||||
|
|
||||||
|
use Carbon\Carbon;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
trait IsPublishable
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Initialize the Trait (Laravel magic method)
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function initializeIsPublishable(): void
|
||||||
|
{
|
||||||
|
/** @var \Illuminate\Database\Eloquent\Model $this */
|
||||||
|
|
||||||
|
$this->mergeCasts([
|
||||||
|
'status' => 'string',
|
||||||
|
'publish_at' => 'datetime',
|
||||||
|
'unpublish_at' => 'datetime',
|
||||||
|
]);
|
||||||
|
$this->mergeFillable([
|
||||||
|
'status',
|
||||||
|
'publish_at',
|
||||||
|
'unpublish_at',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adjusts model status using current status and publish dates
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function makeStatusSense(): void
|
||||||
|
{
|
||||||
|
/** @var \Carbon\Carbon|null */
|
||||||
|
$publish_at = $this->publish_at;
|
||||||
|
/** @var \Carbon\Carbon|null */
|
||||||
|
$unpublish_at = $this->unpublish_at;
|
||||||
|
$wantedStatus = $this->status;
|
||||||
|
if ($publish_at or $unpublish_at) {
|
||||||
|
$this->status = $this->planificated_status;
|
||||||
|
}
|
||||||
|
if ($wantedStatus !== $this->status) {
|
||||||
|
$previousMessage = session()->get('bo.info', '');
|
||||||
|
session()->flash('bo.info', \trans(
|
||||||
|
'La publication est modifiée en concordance avec les dates enregistrées donc
|
||||||
|
pour modifier l\'état de publication, veuillez modifier ou enlever les dates correspondantes.'
|
||||||
|
) . " \n{$previousMessage}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter the current status following planification dates planificated_status
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function getPlanificatedStatusAttribute(): bool
|
||||||
|
{
|
||||||
|
/** @var \Carbon\Carbon */
|
||||||
|
$publish_at = $this->publish_at;
|
||||||
|
/** @var \Carbon\Carbon|null */
|
||||||
|
$unpublish_at = $this->unpublish_at;
|
||||||
|
|
||||||
|
if ($unpublish_at) {
|
||||||
|
return $publish_at->lessThan(now()) && $unpublish_at->greaterThanOrEqualTo(now());
|
||||||
|
}
|
||||||
|
|
||||||
|
return $publish_at->lessThan(now());
|
||||||
|
}
|
||||||
|
|
||||||
|
// * GETTERS / SETTERS (for PHPStan)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get status attribute.
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function getStatus(): bool
|
||||||
|
{
|
||||||
|
return $this->status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set status attribute.
|
||||||
|
*
|
||||||
|
* @param boolean $status
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setStatus(bool $status): void
|
||||||
|
{
|
||||||
|
$this->status = $status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get publish_at attribute.
|
||||||
|
*
|
||||||
|
* @return \Carbon\Carbon|null
|
||||||
|
*/
|
||||||
|
public function getPublishAt(): Carbon|null
|
||||||
|
{
|
||||||
|
return $this->publish_at;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set publish_at attribute.
|
||||||
|
*
|
||||||
|
* @param \Carbon\Carbon|null $date
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setPublishAt(Carbon|null $date): void
|
||||||
|
{
|
||||||
|
$this->publish_at = $date;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get unpublish_at attribute.
|
||||||
|
*
|
||||||
|
* @return \Carbon\Carbon|null
|
||||||
|
*/
|
||||||
|
public function getUnpublishAt(): Carbon|null
|
||||||
|
{
|
||||||
|
return $this->unpublish_at;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set unpublish_at attribute.
|
||||||
|
*
|
||||||
|
* @param \Carbon\Carbon|null $date
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setUnpublishAt(Carbon|null $date): void
|
||||||
|
{
|
||||||
|
$this->unpublish_at = $date;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -12,6 +12,7 @@ trait MiniCrudModel
|
||||||
* Fill the model with an array of attributes.
|
* Fill the model with an array of attributes.
|
||||||
*
|
*
|
||||||
* @param array $attributes
|
* @param array $attributes
|
||||||
|
* @phpstan-ignore-next-line
|
||||||
* @return void
|
* @return void
|
||||||
* @throws \Illuminate\Database\Eloquent\MassAssignmentException If fill prop is not allowed.
|
* @throws \Illuminate\Database\Eloquent\MassAssignmentException If fill prop is not allowed.
|
||||||
* @phpcs:disable Squiz.Commenting.FunctionComment.EmptyThrows
|
* @phpcs:disable Squiz.Commenting.FunctionComment.EmptyThrows
|
||||||
|
|
@ -62,7 +63,6 @@ trait MiniCrudModel
|
||||||
*/
|
*/
|
||||||
public function minicrudUpdated()
|
public function minicrudUpdated()
|
||||||
{
|
{
|
||||||
/** @var array */
|
|
||||||
foreach ($this->data as $index => $input) {
|
foreach ($this->data as $index => $input) {
|
||||||
switch ($input['inputType']) {
|
switch ($input['inputType']) {
|
||||||
case InputType::text->value:
|
case InputType::text->value:
|
||||||
|
|
@ -166,7 +166,7 @@ trait MiniCrudModel
|
||||||
case InputType::string->value:
|
case InputType::string->value:
|
||||||
case InputType::text->value:
|
case InputType::text->value:
|
||||||
case InputType::url->value:
|
case InputType::url->value:
|
||||||
ToolboxHelper::assertNoInternalBoUrls('content', $input['value']);
|
ToolboxHelper::assertNoInternalBoUrls('content', $input['value'] ?? '');
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new \ErrorException(sprintf(
|
throw new \ErrorException(sprintf(
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ trait HasPicture
|
||||||
?int $maxHeight = null,
|
?int $maxHeight = null,
|
||||||
bool $nullable = false
|
bool $nullable = false
|
||||||
): array {
|
): array {
|
||||||
$sizes = (object)[
|
$sizes = (object) [
|
||||||
'minWith' => $minWith ?? $this->minWith,
|
'minWith' => $minWith ?? $this->minWith,
|
||||||
'minHeight' => $minHeight ?? $this->minHeight,
|
'minHeight' => $minHeight ?? $this->minHeight,
|
||||||
'maxWith' => $maxWith ?? $this->maxWith,
|
'maxWith' => $maxWith ?? $this->maxWith,
|
||||||
|
|
@ -66,7 +66,7 @@ trait HasPicture
|
||||||
$name => [
|
$name => [
|
||||||
!$nullable ? 'required' : 'nullable',
|
!$nullable ? 'required' : 'nullable',
|
||||||
function (string $attribute, $value, callable $fail) use ($sizes) {
|
function (string $attribute, $value, callable $fail) use ($sizes) {
|
||||||
return ToolboxHelper::validatePicture($attribute, $value, $fail, $sizes);
|
ToolboxHelper::validatePicture($attribute, $value, $fail, $sizes);
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
@ -89,7 +89,7 @@ trait HasPicture
|
||||||
?int $maxWith = null,
|
?int $maxWith = null,
|
||||||
?int $maxHeight = null
|
?int $maxHeight = null
|
||||||
): array {
|
): array {
|
||||||
$sizes = (object)[
|
$sizes = (object) [
|
||||||
'minWith' => $minWith ?? $this->minWith,
|
'minWith' => $minWith ?? $this->minWith,
|
||||||
'minHeight' => $minHeight ?? $this->minHeight,
|
'minHeight' => $minHeight ?? $this->minHeight,
|
||||||
'maxWith' => $maxWith ?? $this->maxWith,
|
'maxWith' => $maxWith ?? $this->maxWith,
|
||||||
|
|
@ -101,7 +101,7 @@ trait HasPicture
|
||||||
"{$name}Validate.*" => [
|
"{$name}Validate.*" => [
|
||||||
'required',
|
'required',
|
||||||
function (string $attribute, $value, callable $fail) use ($sizes) {
|
function (string $attribute, $value, callable $fail) use ($sizes) {
|
||||||
return $this->validatePicture($attribute, $value, $fail, $sizes);
|
ToolboxHelper::validatePicture($attribute, $value, $fail, $sizes);
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ class RecipeCard extends Component
|
||||||
/**
|
/**
|
||||||
* Recipe model
|
* Recipe model
|
||||||
*
|
*
|
||||||
* @var \App\Recipe
|
* @var \App\Models\Recipe
|
||||||
*/
|
*/
|
||||||
public $recipe;
|
public $recipe;
|
||||||
|
|
||||||
|
|
@ -27,7 +27,7 @@ class RecipeCard extends Component
|
||||||
*/
|
*/
|
||||||
public function __construct(int $id)
|
public function __construct(int $id)
|
||||||
{
|
{
|
||||||
$this->recipe = Recipe::where('id', $id)->first();
|
$this->recipe = Recipe::query()->where('id', $id)->first();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ class RecipeCardSmall extends Component
|
||||||
/**
|
/**
|
||||||
* Recipe model
|
* Recipe model
|
||||||
*
|
*
|
||||||
* @var \App\Recipe
|
* @var \App\Models\Recipe
|
||||||
*/
|
*/
|
||||||
public $recipe;
|
public $recipe;
|
||||||
|
|
||||||
|
|
@ -27,7 +27,7 @@ class RecipeCardSmall extends Component
|
||||||
*/
|
*/
|
||||||
public function __construct(int $id)
|
public function __construct(int $id)
|
||||||
{
|
{
|
||||||
$this->recipe = Recipe::where('id', $id)->first();
|
$this->recipe = Recipe::query()->where('id', $id)->first();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ class RecipeProductStoerer extends Component
|
||||||
/**
|
/**
|
||||||
* product variable
|
* product variable
|
||||||
*
|
*
|
||||||
* @var \App\Product
|
* @var \App\Models\Product
|
||||||
*/
|
*/
|
||||||
public $product;
|
public $product;
|
||||||
|
|
||||||
|
|
@ -29,7 +29,7 @@ class RecipeProductStoerer extends Component
|
||||||
*/
|
*/
|
||||||
public function __construct(int $id)
|
public function __construct(int $id)
|
||||||
{
|
{
|
||||||
$this->product = Product::where('id', $id)->first();
|
$this->product = Product::query()->where('id', $id)->first();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ class RecipeWidget extends Component
|
||||||
/**
|
/**
|
||||||
* recipes variable
|
* recipes variable
|
||||||
*
|
*
|
||||||
* @var \App\Recipe
|
* @var \Illuminate\Database\Eloquent\Collection<\App\Models\Recipe>
|
||||||
*/
|
*/
|
||||||
private $recipes;
|
private $recipes;
|
||||||
|
|
||||||
|
|
@ -43,10 +43,10 @@ class RecipeWidget extends Component
|
||||||
}
|
}
|
||||||
if ($id != null) {
|
if ($id != null) {
|
||||||
$this->id = $id;
|
$this->id = $id;
|
||||||
$this->recipes = Recipe::where('status', '1')
|
$this->recipes = Recipe::query()->where('status', '1')
|
||||||
->where('id', '!=', $this->id)->inRandomOrder()->limit($this->limit)->get();
|
->where('id', '!=', $this->id)->inRandomOrder()->limit($this->limit)->get();
|
||||||
} else {
|
} else {
|
||||||
$this->recipes = Recipe::where('status', '1')->inRandomOrder()->limit($this->limit)->get();
|
$this->recipes = Recipe::query()->where('status', '1')->inRandomOrder()->limit($this->limit)->get();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
1
commitlint.config.js
Normal file
1
commitlint.config.js
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
export default { extends: ["@uwil/husky-config/commitlint.config.js"] };
|
||||||
|
|
@ -1,44 +1,42 @@
|
||||||
{
|
{
|
||||||
"name": "ldcweb/wenn-dann-mit-respekt",
|
"name": "uwil/nature-and-respect",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"type": "project",
|
"type": "project",
|
||||||
"time": "2023-03-16",
|
"time": "2023-03-16",
|
||||||
"description": "Website of Wenn dann mit respekt.",
|
"description": "Website of Nature & Respect.",
|
||||||
"support": {
|
|
||||||
"email": "equipe.web@ldc.fr"
|
|
||||||
},
|
|
||||||
"keywords": [
|
|
||||||
"framework",
|
|
||||||
"laravel"
|
|
||||||
],
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"require": {
|
"require": {
|
||||||
"php": "^8.1",
|
"php": "^8.5",
|
||||||
"codezero/laravel-localized-routes": "^3.1",
|
"codezero/laravel-localized-routes": "^4.0.1",
|
||||||
"codezero/laravel-unique-translation": "^4.1",
|
"codezero/laravel-unique-translation": "^4.3.1",
|
||||||
"diglactic/laravel-breadcrumbs": "^8.0",
|
"diglactic/laravel-breadcrumbs": "^9.0.0",
|
||||||
"guzzlehttp/guzzle": "^7.2",
|
"guzzlehttp/guzzle": "^7.2",
|
||||||
"kwaadpepper/refresh-sitemap": "^2.0",
|
"kwaadpepper/image-resizer": "^3.1.0",
|
||||||
"laravel/framework": "^10.0",
|
"laravel/framework": "^11.0",
|
||||||
"laravel/tinker": "^2.8",
|
"laravel/tinker": "^2.8",
|
||||||
"laravel/ui": "^4.2",
|
"laravel/ui": "^4.2",
|
||||||
"mews/purifier": "^3.4",
|
"mews/purifier": "^3.4",
|
||||||
"sentry/sentry-laravel": "^3.3",
|
"sentry/sentry-laravel": "^4.15.1",
|
||||||
"simplesoftwareio/simple-qrcode": "~4",
|
"simplesoftwareio/simple-qrcode": "^4.2.0",
|
||||||
"spatie/laravel-translatable": "^6.4",
|
"spatie/laravel-translatable": "^6.4",
|
||||||
"uwil/k8s-laravel": "1.0.0"
|
"uwil/admin-secure-laravel": "^5.0",
|
||||||
|
"uwil/k8s-laravel": "^2.0.0",
|
||||||
|
"uwil/laravel-common": "^4.1.6",
|
||||||
|
"uwil/schema-org-laravel": "^2.2.0",
|
||||||
|
"uwil/seo-laravel": "^4.0.0",
|
||||||
|
"uwil/sitemap-generator": "^5.0.1"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"fakerphp/faker": "^1.9.1",
|
"fakerphp/faker": "^1.9.1",
|
||||||
"kitloong/laravel-migrations-generator": "^6.8",
|
"kitloong/laravel-migrations-generator": "^7.0.0",
|
||||||
"krlove/eloquent-model-generator": "dev-l10-compatibility",
|
"larastan/larastan": "^2.6",
|
||||||
"laravel-lang/common": "^3.1",
|
"laravel-lang/common": "^3.1",
|
||||||
"laravel/pint": "^1.0",
|
"laravel/pint": "^1.0",
|
||||||
"laravel/sail": "^1.18",
|
"laravel/sail": "^1.18",
|
||||||
"mockery/mockery": "^1.4.4",
|
"mockery/mockery": "^1.4.4",
|
||||||
"nunomaduro/collision": "^7.0",
|
"nunomaduro/collision": "^8.1",
|
||||||
"phpunit/phpunit": "^10.0",
|
"phpunit/phpunit": "^10.0",
|
||||||
"slevomat/coding-standard": "^8.10",
|
"slevomat/coding-standard": "^8.19",
|
||||||
"spatie/laravel-ignition": "^2.0",
|
"spatie/laravel-ignition": "^2.0",
|
||||||
"thedoctor0/laravel-factory-generator": "^1.2"
|
"thedoctor0/laravel-factory-generator": "^1.2"
|
||||||
},
|
},
|
||||||
|
|
@ -75,6 +73,12 @@
|
||||||
],
|
],
|
||||||
"post-create-project-cmd": [
|
"post-create-project-cmd": [
|
||||||
"@php artisan key:generate --ansi"
|
"@php artisan key:generate --ansi"
|
||||||
|
],
|
||||||
|
"phpcs": [
|
||||||
|
"./vendor/bin/phpcs"
|
||||||
|
],
|
||||||
|
"phpstan": [
|
||||||
|
"./vendor/bin/phpstan"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"extra": {
|
"extra": {
|
||||||
|
|
|
||||||
6915
composer.lock
generated
6915
composer.lock
generated
File diff suppressed because it is too large
Load diff
|
|
@ -41,7 +41,7 @@ return [
|
||||||
|
|
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
'debug' => (bool)env('APP_DEBUG', false),
|
'debug' => (bool) env('APP_DEBUG', false),
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,6 @@ return [
|
||||||
|
|
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// 'paths' => ['api/*', 'sanctum/csrf-cookie', '*/storefinder'],
|
|
||||||
'paths' => ['*'],
|
'paths' => ['*'],
|
||||||
|
|
||||||
'allowed_methods' => ['*'],
|
'allowed_methods' => ['*'],
|
||||||
|
|
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue