Compare commits
1 commit
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
06b8921dba |
553 changed files with 37810 additions and 40392 deletions
|
|
@ -1,5 +0,0 @@
|
|||
# Browsers that we support
|
||||
|
||||
last 3 version
|
||||
> 0.3%
|
||||
not dead # no browsers without security updates
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
.git
|
||||
*.md
|
||||
|
|
@ -3,9 +3,9 @@ root = true
|
|||
[*]
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
indent_size = 4
|
||||
indent_style = space
|
||||
insert_final_newline = true
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[*.md]
|
||||
|
|
@ -14,8 +14,8 @@ trim_trailing_whitespace = false
|
|||
[*.{yml,yaml}]
|
||||
indent_size = 2
|
||||
|
||||
[docker-compose.yml]
|
||||
indent_size = 4
|
||||
|
||||
[*.vue]
|
||||
indent_size = 2
|
||||
|
||||
[docker-compose.yml]
|
||||
indent_size = 4
|
||||
|
|
|
|||
22
.env.example
22
.env.example
|
|
@ -43,21 +43,9 @@ GOOGLE_RECAPTCHA_PUBLIC=
|
|||
GOOGLE_RECAPTCHA_PRIVATE=
|
||||
GOOGLE_RECAPTCHA_VERSION=
|
||||
|
||||
# UWIL ADMIN SECURE
|
||||
# - LIST SEPARATED WITH ',' (Required)
|
||||
UWIL_ADMIN_SECURE_CIDR_LIST=""
|
||||
# - LIST SEPARATED WITH ',' (Optional)
|
||||
UWIL_ADMIN_SECURE_CIDR_PROJECT_ALLOWED_LIST=""
|
||||
# LDC Web Status Checker
|
||||
LDC_STATUS_CHECKER_API_KEY="MY_KEY"
|
||||
LDC_STATUS_CHECKER_UUID="UUID_PROJECT"
|
||||
|
||||
|
||||
# SAML
|
||||
SAML2_DEFAULT_TENANT_UUID=
|
||||
SAML2_SP_CERT_x509=
|
||||
SAML2_SP_CERT_PRIVATEKEY=
|
||||
SAML2_CONTACT_TECHNICAL_EMAIL=
|
||||
SAML2_CONTACT_SUPPORT_EMAIL=
|
||||
|
||||
# CRM
|
||||
CRM_ENDPOINT=
|
||||
CRM_PASSWORD=
|
||||
CRM_TOKEN=
|
||||
# LDC Web Admin Secure
|
||||
LDC_WEB_API_KEY="MY_KEY"
|
||||
|
|
|
|||
|
|
@ -29,14 +29,7 @@
|
|||
"sourceType": "module"
|
||||
},
|
||||
"plugins": ["vue", "@typescript-eslint"],
|
||||
"ignorePatterns": [
|
||||
"webpack.mix.js",
|
||||
"**/*.php",
|
||||
"**/*.svg",
|
||||
"**/vendor/*.js",
|
||||
"**/vendor/**/*.js",
|
||||
"**/vendor/**/*.scss"
|
||||
],
|
||||
"ignorePatterns": ["webpack.mix.js", "**/vendor/*.js", "**/vendor/**/*.js"],
|
||||
"rules": {
|
||||
"indent": ["error", 4, { "SwitchCase": 1 }],
|
||||
"linebreak-style": ["error", "unix"],
|
||||
|
|
@ -44,19 +37,5 @@
|
|||
"semi": ["error", "always"],
|
||||
"vue/script-indent": ["error", 2, { "baseIndent": 0, "switchCase": 1 }],
|
||||
"vue/one-component-per-file": "off"
|
||||
},
|
||||
"settings": {
|
||||
"import/resolver": {
|
||||
"node": {
|
||||
"extensions": [".js", ".vue", ".ts", ".d.ts"]
|
||||
},
|
||||
"alias": {
|
||||
"extensions": [".vue", ".js", ".ts", ".scss", ".d.ts"],
|
||||
"map": [
|
||||
["~", "./resources/assets"],
|
||||
["@", "./node_modules"]
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
3
.gitattributes
vendored
3
.gitattributes
vendored
|
|
@ -1,4 +1,4 @@
|
|||
* text=auto eol=lf
|
||||
* text=auto
|
||||
|
||||
*.blade.php diff=html
|
||||
*.css diff=css
|
||||
|
|
@ -8,4 +8,3 @@
|
|||
|
||||
/.github export-ignore
|
||||
CHANGELOG.md export-ignore
|
||||
.styleci.yml export-ignore
|
||||
|
|
|
|||
42
.gitignore
vendored
42
.gitignore
vendored
|
|
@ -1,41 +1,21 @@
|
|||
.env
|
||||
.env.backup
|
||||
.env.production
|
||||
.phpunit.result.cache
|
||||
.stylelintcache
|
||||
/.fleet
|
||||
/.idea
|
||||
/.phpunit.cache
|
||||
/.vscode
|
||||
/node_modules
|
||||
/bootstrap
|
||||
/public/build
|
||||
/public/cache
|
||||
/public/hot
|
||||
/public/sitemap.xml
|
||||
/public/storage
|
||||
/public/build
|
||||
/public/medias
|
||||
/public/uploads
|
||||
/public/cache
|
||||
/public/sitemap.xml
|
||||
/storage/*.key
|
||||
/vendor
|
||||
auth.json
|
||||
.env
|
||||
.env.backup
|
||||
.phpunit.result.cache
|
||||
docker-compose.override.yml
|
||||
Homestead.json
|
||||
Homestead.yaml
|
||||
npm-debug.log
|
||||
yarn-error.log
|
||||
.npmrc
|
||||
.zshrc
|
||||
.npm/
|
||||
.composer/
|
||||
|
||||
# Ignore public favicon
|
||||
/public/android-chrome-192x192.png
|
||||
/public/android-chrome-512x512.png
|
||||
/public/apple-touch-icon.png
|
||||
/public/browserconfig.xml
|
||||
/public/browserconfig.xml
|
||||
/public/favicon-16x16.png
|
||||
/public/favicon-32x32.png
|
||||
/public/favicon.ico
|
||||
/public/mstile-150x150.png
|
||||
/public/safari-pinned-tab.svg
|
||||
/public/site.webmanifest
|
||||
/.idea
|
||||
/.vscode
|
||||
auth.json
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
include:
|
||||
- project: 'ldc-web/shared-ci'
|
||||
ref: 'main'
|
||||
file: 'lint/lint.yml'
|
||||
file: 'lint/lint7.3.yml'
|
||||
- project: 'ldc-web/shared-ci'
|
||||
ref: 'main'
|
||||
file: 'security/security.yml'
|
||||
file: 'security/security7.3.yml'
|
||||
- project: 'ldc-web/shared-ci'
|
||||
ref: 'main'
|
||||
file: 'build/docker-multistage.yml'
|
||||
file: 'build/build7.3.yml'
|
||||
- project: 'ldc-web/shared-ci'
|
||||
ref: 'main'
|
||||
file: 'test/test.yml'
|
||||
|
|
@ -21,4 +21,4 @@ stages:
|
|||
- security
|
||||
- build
|
||||
- test
|
||||
- deploy
|
||||
- deploy
|
||||
|
|
@ -4,13 +4,8 @@
|
|||
"stylelint-config-sass-guidelines",
|
||||
"stylelint-config-idiomatic-order"
|
||||
],
|
||||
"plugins": [
|
||||
"stylelint-scss"
|
||||
],
|
||||
"files": [
|
||||
"**/*.css",
|
||||
"**/*.scss"
|
||||
],
|
||||
"plugins": ["stylelint-scss"],
|
||||
"files": ["**/*.css", "**/*.scss"],
|
||||
"ignoreFiles": [
|
||||
"**/vendor/*.css",
|
||||
"**/vendor/**/*.css",
|
||||
|
|
@ -23,14 +18,13 @@
|
|||
],
|
||||
"customSyntax": "postcss-scss",
|
||||
"rules": {
|
||||
"declaration-property-value-no-unknown": true,
|
||||
"indentation": 4,
|
||||
"string-quotes": "double",
|
||||
"selector-max-id": null,
|
||||
"color-no-invalid-hex": true,
|
||||
"order/properties-alphabetical-order": null,
|
||||
"max-nesting-depth": 5,
|
||||
"selector-max-compound-selectors": 5,
|
||||
"declaration-colon-newline-after": null,
|
||||
"value-list-comma-newline-after": null,
|
||||
"scss/double-slash-comment-empty-line-before": [
|
||||
"always",
|
||||
{
|
||||
|
|
|
|||
7
.vscode/settings.json
vendored
7
.vscode/settings.json
vendored
|
|
@ -1,4 +1,5 @@
|
|||
{
|
||||
"peacock.remoteColor": "#006ea3",
|
||||
"workbench.colorCustomizations": {
|
||||
"activityBar.activeBackground": "#0090d6",
|
||||
"activityBar.background": "#0090d6",
|
||||
|
|
@ -17,9 +18,5 @@
|
|||
"titleBar.activeForeground": "#e7e7e7",
|
||||
"titleBar.inactiveBackground": "#006ea399",
|
||||
"titleBar.inactiveForeground": "#e7e7e799"
|
||||
},
|
||||
"peacock.remoteColor": "#006ea3",
|
||||
"intelephense.environment.phpVersion": "8.2.0",
|
||||
"intelephense.completion.fullyQualifyGlobalConstantsAndFunctions": true,
|
||||
"intelephense.phpdoc.useFullyQualifiedNames": true
|
||||
}
|
||||
}
|
||||
|
|
|
|||
22
CHANGELOG.md
22
CHANGELOG.md
|
|
@ -1,22 +1,10 @@
|
|||
# Changelog
|
||||
|
||||
## 18/12/23
|
||||
|
||||
Fixes + bump front stack
|
||||
|
||||
## 18/09/2023
|
||||
|
||||
bump laravel 10 + update with base project
|
||||
|
||||
## 01/08/2022
|
||||
|
||||
init
|
||||
# 01/08/2022
|
||||
init
|
||||
with packages :
|
||||
|
||||
- kwaadpepper/exception-handler
|
||||
- kwaadpepper/refresh-sitemap
|
||||
- ldc/web-admin-secure-laravel
|
||||
- ldc/web-status-checker-laravel
|
||||
- ldc/web-status-checker-laravel
|
||||
|
||||
with Google Services keys
|
||||
with gitlab-ci config file
|
||||
with Google Services keys
|
||||
with gitlab-ci config file
|
||||
51
Dockerfile
51
Dockerfile
|
|
@ -1,47 +1,4 @@
|
|||
ARG PHP_8_5_TAG=latest
|
||||
|
||||
FROM composer:2.8 AS vendor
|
||||
|
||||
ARG GITLAB_USER
|
||||
ARG GITLAB_PASSWORD
|
||||
|
||||
COPY database/ database/
|
||||
|
||||
COPY composer.json composer.json
|
||||
COPY composer.lock composer.lock
|
||||
|
||||
RUN composer config gitlab-token.lab.s-web.fr ${GITLAB_USER} ${GITLAB_PASSWORD}
|
||||
RUN composer install \
|
||||
--ignore-platform-reqs \
|
||||
--no-interaction \
|
||||
--no-plugins \
|
||||
--no-scripts \
|
||||
--no-dev \
|
||||
--prefer-dist
|
||||
|
||||
FROM node:20.18 AS frontend
|
||||
|
||||
ARG GITLAB_PASSWORD
|
||||
|
||||
RUN mkdir -p /app/public/build
|
||||
|
||||
COPY package*.json tsconfig.json vite.config.ts .eslintrc.json .stylelintrc.json /app/
|
||||
COPY resources/ /app/resources/
|
||||
WORKDIR /app
|
||||
RUN npm config set @ldc-web:registry https://lab.s-web.fr/api/v4/packages/npm/
|
||||
RUN npm config set -- '//lab.s-web.fr/api/v4/packages/npm/:_authToken' "${GITLAB_PASSWORD}"
|
||||
RUN npm ci && npm run prod
|
||||
|
||||
ARG PHP_8_5_TAG
|
||||
FROM registry.s-web.fr/ldc-web/projets/ldc-web-images-docker/uwil-production-8.5:${PHP_8_5_TAG}
|
||||
|
||||
ARG USER=www-data
|
||||
|
||||
COPY --chown=${USER}:${USER} . /app/srcs
|
||||
COPY --chown=${USER}:${USER} ./resources/favicon /app/srcs/public
|
||||
COPY --from=vendor --chown=${USER}:${USER} /app/vendor/ /app/srcs/vendor/
|
||||
COPY --from=frontend --chown=${USER}:${USER} /app/public/build/ /app/srcs/public/build/
|
||||
|
||||
USER root
|
||||
RUN chmod -R 755 /app/srcs/storage
|
||||
USER ${USER}
|
||||
FROM registry.s-web.fr/ldc-web/projets/ldc-web-images-docker/ldcweb-production-7.3:latest
|
||||
COPY . /app/srcs
|
||||
COPY ./public/build /app/srcs/public/build
|
||||
COPY ./vendor /app/srcs/vendor
|
||||
|
|
@ -15,10 +15,10 @@ class HtmlColor implements CastsAttributes
|
|||
/**
|
||||
* Cast the given value.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Model $model
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param array $attributes
|
||||
* @param Model $model
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param array $attributes
|
||||
* @return string
|
||||
* @phpcs:disable Squiz.Commenting.FunctionComment.TypeHintMissing
|
||||
* @phpcs:disable Squiz.Commenting.FunctionComment.ScalarTypeHintMissing
|
||||
|
|
@ -32,10 +32,10 @@ class HtmlColor implements CastsAttributes
|
|||
/**
|
||||
* Prepare the given value for storage.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Model $model
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param array $attributes
|
||||
* @param Model $model
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param array $attributes
|
||||
* @return integer
|
||||
* @phpcs:disable Squiz.Commenting.FunctionComment.TypeHintMissing
|
||||
* @phpcs:disable Squiz.Commenting.FunctionComment.ScalarTypeHintMissing
|
||||
|
|
|
|||
|
|
@ -11,10 +11,10 @@ class RgbaColor extends HtmlColor
|
|||
/**
|
||||
* Cast the given value.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Model $model
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param array $attributes
|
||||
* @param Model $model
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param array $attributes
|
||||
* @return string
|
||||
* @phpcs:disable Squiz.Commenting.FunctionComment.TypeHintMissing
|
||||
* @phpcs:disable Squiz.Commenting.FunctionComment.ScalarTypeHintMissing
|
||||
|
|
@ -24,7 +24,6 @@ class RgbaColor extends HtmlColor
|
|||
public function get($model, $key, $value, $attributes)
|
||||
{
|
||||
// phpcs:enable
|
||||
/** @var \Illuminate\Support\Collection<array-key,int|float> */
|
||||
$intValues = collect(\str_split($this->zeropad(\dechex(\intval($value)), 8), 2))->map(function ($hex) {
|
||||
return intval(\hexdec($hex));
|
||||
});
|
||||
|
|
@ -36,10 +35,10 @@ class RgbaColor extends HtmlColor
|
|||
/**
|
||||
* Prepare the given value for storage.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Model $model
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param array $attributes
|
||||
* @param Model $model
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param array $attributes
|
||||
* @return integer
|
||||
* @phpcs:disable Squiz.Commenting.FunctionComment.TypeHintMissing
|
||||
* @phpcs:disable Squiz.Commenting.FunctionComment.ScalarTypeHintMissing
|
||||
|
|
|
|||
90
app/Console/Commands/CreateAdmin.php
Normal file
90
app/Console/Commands/CreateAdmin.php
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
/**
|
||||
* Creates a new user
|
||||
*/
|
||||
class CreateAdmin extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'user:create';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Create a backend admin user';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$email = null;
|
||||
while (is_null($email)) {
|
||||
try {
|
||||
$tmp = $this->ask('Type the wanted user email', 'equipe.web@ldc.fr');
|
||||
$validator = Validator::make(['email' => $tmp], [
|
||||
'email' => 'required|unique:users,email|email:rfc,dns'
|
||||
]);
|
||||
$validator->validate();
|
||||
$email = $tmp;
|
||||
} catch (ValidationException $e) {
|
||||
$this->error(sprintf(
|
||||
'Please provide a valid email %s',
|
||||
\implode(',', collect($e->errors())->flatten()->all())
|
||||
));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
$name = null;
|
||||
while (is_null($name)) {
|
||||
try {
|
||||
$tmp = $this->ask('Type the wanted user name', 'Admin');
|
||||
$validator = Validator::make(['name' => $tmp], [
|
||||
'name' => 'required|min:5,max:255'
|
||||
]);
|
||||
$validator->validate();
|
||||
$name = $tmp;
|
||||
} catch (ValidationException $e) {
|
||||
$this->error(sprintf(
|
||||
'Please provide a valid name %s',
|
||||
\implode(',', collect($e->errors())->flatten()->all())
|
||||
));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$password = null;
|
||||
while (
|
||||
($password = $this->secret(
|
||||
(!\is_null($password) ? 'Failed to confirm, ' : '') . 'Type the wanted user password'
|
||||
)) !== $this->secret('Confirm the password')
|
||||
) {
|
||||
continue;
|
||||
};
|
||||
|
||||
$admin = new User([
|
||||
'name' => $name,
|
||||
'email' => $email,
|
||||
'password' => $password
|
||||
]);
|
||||
$admin->saveOrFail();
|
||||
|
||||
$this->info('User created.');
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,149 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
class UserCreate extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'uwil:user:create';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Create a backend admin user';
|
||||
|
||||
/**
|
||||
* The first name of the new user.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $firstname;
|
||||
|
||||
/**
|
||||
* The last name of the new user.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $lastname;
|
||||
|
||||
/**
|
||||
* The email of the new user.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $email;
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
$this->firstname = null;
|
||||
$this->addFirstName();
|
||||
|
||||
$this->lastname = null;
|
||||
$this->addLastName();
|
||||
|
||||
$this->email = null;
|
||||
$this->addEmail();
|
||||
|
||||
$user = new User([
|
||||
'firstname' => $this->firstname,
|
||||
'lastname' => $this->lastname,
|
||||
'email' => $this->email
|
||||
]);
|
||||
$user->saveOrFail();
|
||||
|
||||
$this->info('User created 👌');
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a first name to the user.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function addFirstName(): void
|
||||
{
|
||||
while (is_null($this->firstname)) {
|
||||
try {
|
||||
$tmp = $this->ask('Type the wanted user first name', 'Admin');
|
||||
$validator = Validator::make(['firstname' => $tmp], [
|
||||
'firstname' => 'required|min:3|max:255'
|
||||
]);
|
||||
$validator->validate();
|
||||
$this->firstname = $tmp;
|
||||
} catch (ValidationException $e) {
|
||||
$this->error(sprintf(
|
||||
'Please provide a valid first name %s',
|
||||
\implode(',', collect($e->errors())->flatten()->all())
|
||||
));
|
||||
continue;
|
||||
} //end try
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a last name to the user.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function addLastName(): void
|
||||
{
|
||||
while (is_null($this->lastname)) {
|
||||
try {
|
||||
$tmp = $this->ask('Type the wanted user last name', 'Saïtama');
|
||||
$validator = Validator::make(['lastname' => $tmp], [
|
||||
'lastname' => 'required|min:3|max:255'
|
||||
]);
|
||||
$validator->validate();
|
||||
$this->lastname = $tmp;
|
||||
} catch (ValidationException $e) {
|
||||
$this->error(sprintf(
|
||||
'Please provide a valid lastname %s',
|
||||
\implode(',', collect($e->errors())->flatten()->all())
|
||||
));
|
||||
continue;
|
||||
} //end try
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an email to the user.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function addEmail(): void
|
||||
{
|
||||
while (is_null($this->email)) {
|
||||
try {
|
||||
$tmp = $this->ask('Type the wanted user email', 'equipe.web@ldc.fr');
|
||||
$validator = Validator::make(['email' => $tmp], [
|
||||
'email' => 'required|unique:users,email|email:rfc,dns'
|
||||
]);
|
||||
$validator->validate();
|
||||
$this->email = $tmp;
|
||||
} catch (ValidationException $e) {
|
||||
$this->error(sprintf(
|
||||
'Please provide a valid email %s',
|
||||
\implode(',', collect($e->errors())->flatten()->all())
|
||||
));
|
||||
continue;
|
||||
} //end try
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -2,24 +2,40 @@
|
|||
|
||||
namespace App\Enums\Advices;
|
||||
|
||||
use App\Traits\Enums\BaseEnum;
|
||||
use Kwaadpepper\Enum\BaseEnum;
|
||||
|
||||
enum AdviceDifficultyEnum: int
|
||||
/**
|
||||
* @method static self easy()
|
||||
* @method static self medium()
|
||||
* @method static self hard()
|
||||
*/
|
||||
final class AdviceDifficultyEnum extends BaseEnum
|
||||
{
|
||||
use BaseEnum;
|
||||
|
||||
case easy = 0;
|
||||
case medium = 1;
|
||||
case hard = 2;
|
||||
/**
|
||||
* Enum values
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected static function values(): array
|
||||
{
|
||||
return [
|
||||
'easy' => 0,
|
||||
'medium' => 1,
|
||||
'hard' => 2
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Optionnal labels definition.
|
||||
* Enum labels
|
||||
*
|
||||
* @phpstan-ignore-next-line
|
||||
* @return array
|
||||
*/
|
||||
private const LABELS = [
|
||||
self::easy->name => 'Facile',
|
||||
self::medium->name => 'Moyen',
|
||||
self::hard->name => 'Difficile',
|
||||
];
|
||||
protected static function labels(): array
|
||||
{
|
||||
return [
|
||||
'easy' => trans('Facile'),
|
||||
'medium' => trans('Moyen'),
|
||||
'hard' => trans('Difficile')
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,46 +2,70 @@
|
|||
|
||||
namespace App\Enums\Advices;
|
||||
|
||||
use App\Traits\Enums\BaseEnum;
|
||||
use Kwaadpepper\Enum\BaseEnum;
|
||||
|
||||
enum AdviceTimeEnum: int
|
||||
/**
|
||||
* @method static self first()
|
||||
* @method static self second()
|
||||
* @method static self third()
|
||||
* @method static self fourth()
|
||||
*/
|
||||
final class AdviceTimeEnum extends BaseEnum
|
||||
{
|
||||
use BaseEnum;
|
||||
|
||||
case first = 1;
|
||||
case second = 2;
|
||||
case third = 3;
|
||||
case fourth = 4;
|
||||
|
||||
/**
|
||||
* Optionnal labels definition.
|
||||
*
|
||||
* @phpstan-ignore-next-line
|
||||
*/
|
||||
private const LABELS = [
|
||||
self::first->name => '0 - 30min',
|
||||
self::second->name => '31min - 2h',
|
||||
self::third->name => '2h - 4h',
|
||||
self::fourth->name => '> 4h',
|
||||
];
|
||||
|
||||
/**
|
||||
* Optionnal labels definition.
|
||||
*/
|
||||
private const TIMES = [
|
||||
'first' => [0, 30],
|
||||
'second' => [31, 120],
|
||||
'third' => [120, 240],
|
||||
'fourth' => [240, 1440]
|
||||
];
|
||||
|
||||
/**
|
||||
* Get time.
|
||||
* Enum values
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function times(): array
|
||||
protected static function values(): array
|
||||
{
|
||||
return self::TIMES[$this->name];
|
||||
return [
|
||||
'first' => 1,
|
||||
'second' => 2,
|
||||
'third' => 3,
|
||||
'fourth' => 4,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Enum labels
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected static function labels(): array
|
||||
{
|
||||
return [
|
||||
'first' => trans('0 - 30min'),
|
||||
'second' => trans('31min - 2h'),
|
||||
'third' => trans('2h - 4h'),
|
||||
'fourth' => trans('> 4h'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Enum times
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected static function times(): array
|
||||
{
|
||||
return [
|
||||
'first' => [0, 30],
|
||||
'second' => [31, 120],
|
||||
'third' => [120, 240],
|
||||
'fourth' => [240, 1440]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $attribute
|
||||
* @return integer|string
|
||||
*/
|
||||
public function __get(string $attribute)
|
||||
{
|
||||
if ($attribute === 'times') {
|
||||
return $this->times()[$this->getDefinition()] ?? null;
|
||||
}
|
||||
return parent::__get($attribute);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,24 +2,40 @@
|
|||
|
||||
namespace App\Enums\Advices;
|
||||
|
||||
use App\Traits\Enums\BaseEnum;
|
||||
use Kwaadpepper\Enum\BaseEnum;
|
||||
|
||||
enum AdviceTypeEnum: string
|
||||
/**
|
||||
* @method static self all()
|
||||
* @method static self recipes()
|
||||
* @method static self tips()
|
||||
*/
|
||||
final class AdviceTypeEnum extends BaseEnum
|
||||
{
|
||||
use BaseEnum;
|
||||
|
||||
case all = '0';
|
||||
case recipes = '1';
|
||||
case tips = '2';
|
||||
/**
|
||||
* Enum values
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected static function values(): array
|
||||
{
|
||||
return [
|
||||
'all' => 0,
|
||||
'recipes' => 1,
|
||||
'tips' => 2,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Optionnal labels definition
|
||||
* Enum labels
|
||||
*
|
||||
* @phpstan-ignore-next-line
|
||||
* @return array
|
||||
*/
|
||||
private const LABELS = [
|
||||
self::all->name => 'Recettes / Astuces',
|
||||
self::recipes->name => 'Recettes',
|
||||
self::tips->name => 'Astuces',
|
||||
];
|
||||
protected static function labels(): array
|
||||
{
|
||||
return [
|
||||
'all' => trans('Recettes / Astuces'),
|
||||
'recipes' => trans('Recettes'),
|
||||
'tips' => trans('Astuces'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,30 +2,49 @@
|
|||
|
||||
namespace App\Enums\Contact;
|
||||
|
||||
use App\Traits\Enums\BaseEnum;
|
||||
use Kwaadpepper\Enum\BaseEnum;
|
||||
|
||||
enum ContactActivityEnum: int
|
||||
/**
|
||||
* @method static self distributeur()
|
||||
* @method static self restaurationSociale()
|
||||
* @method static self restaurationCommerciale()
|
||||
* @method static self boulangeriePatisserie()
|
||||
* @method static self journaliste()
|
||||
* @method static self autre()
|
||||
*/
|
||||
final class ContactActivityEnum extends BaseEnum
|
||||
{
|
||||
use BaseEnum;
|
||||
|
||||
case distributeur = 1;
|
||||
case restaurationSociale = 2;
|
||||
case restaurationCommerciale = 3;
|
||||
case boulangeriePatisserie = 4;
|
||||
case journaliste = 5;
|
||||
case autre = 6;
|
||||
/**
|
||||
* Enum values
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected static function values(): array
|
||||
{
|
||||
return [
|
||||
'distributeur' => 1,
|
||||
'restaurationSociale' => 2,
|
||||
'restaurationCommerciale' => 3,
|
||||
'boulangeriePatisserie' => 4,
|
||||
'journaliste' => 5,
|
||||
'autre' => 6
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Optionnal labels definition.
|
||||
* Enum labels
|
||||
*
|
||||
* @phpstan-ignore-next-line
|
||||
* @return array
|
||||
*/
|
||||
private const LABELS = [
|
||||
self::distributeur->name => 'Distributeur',
|
||||
self::restaurationSociale->name => 'Restauration sociale',
|
||||
self::restaurationCommerciale->name => 'Restauration commerciale',
|
||||
self::boulangeriePatisserie->name => 'Boulangerie-pâtisserie',
|
||||
self::journaliste->name => 'Journaliste',
|
||||
self::autre->name => 'Autre',
|
||||
];
|
||||
protected static function labels(): array
|
||||
{
|
||||
return [
|
||||
'distributeur' => trans('Distributeur'),
|
||||
'restaurationSociale' => trans('Restauration sociale'),
|
||||
'restaurationCommerciale' => trans('Restauration commerciale'),
|
||||
'boulangeriePatisserie' => trans('Boulangerie-pâtisserie'),
|
||||
'journaliste' => trans('Journaliste'),
|
||||
'autre' => trans('Autre'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,24 +2,40 @@
|
|||
|
||||
namespace App\Enums\Contact;
|
||||
|
||||
use App\Traits\Enums\BaseEnum;
|
||||
use Kwaadpepper\Enum\BaseEnum;
|
||||
|
||||
enum ContactTimeEnum: int
|
||||
/**
|
||||
* @method static self morning()
|
||||
* @method static self afternoon()
|
||||
* @method static self anytime()
|
||||
*/
|
||||
final class ContactTimeEnum extends BaseEnum
|
||||
{
|
||||
use BaseEnum;
|
||||
|
||||
case morning = 1;
|
||||
case afternoon = 2;
|
||||
case anytime = 3;
|
||||
/**
|
||||
* Enum values
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected static function values(): array
|
||||
{
|
||||
return [
|
||||
'morning' => 1,
|
||||
'afternoon' => 2,
|
||||
'anytime' => 3,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Optionnal labels definition.
|
||||
* Enum labels
|
||||
*
|
||||
* @phpstan-ignore-next-line
|
||||
* @return array
|
||||
*/
|
||||
private const LABELS = [
|
||||
self::morning->name => 'Le matin',
|
||||
self::afternoon->name => 'L\'après-midi',
|
||||
self::anytime->name => 'À tout moment',
|
||||
];
|
||||
protected static function labels(): array
|
||||
{
|
||||
return [
|
||||
'morning' => trans('Le matin'),
|
||||
'afternoon' => trans('L\'après-midi'),
|
||||
'anytime' => trans('À tout moment'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,28 +2,46 @@
|
|||
|
||||
namespace App\Enums\ExpertiseProducts;
|
||||
|
||||
use App\Traits\Enums\BaseEnum;
|
||||
use Kwaadpepper\Enum\BaseEnum;
|
||||
|
||||
enum ExpertiseProductPageEnum: int
|
||||
/**
|
||||
* @method static self duck()
|
||||
* @method static self turkey()
|
||||
* @method static self rabbit()
|
||||
* @method static self guineafowl()
|
||||
* @method static self chicken()
|
||||
*/
|
||||
final class ExpertiseProductPageEnum extends BaseEnum
|
||||
{
|
||||
use BaseEnum;
|
||||
|
||||
case duck = 0;
|
||||
case turkey = 1;
|
||||
case rabbit = 2;
|
||||
case guineafowl = 3;
|
||||
case chicken = 4;
|
||||
/**
|
||||
* Enum values
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected static function values(): array
|
||||
{
|
||||
return [
|
||||
'duck' => 0,
|
||||
'turkey' => 1,
|
||||
'rabbit' => 2,
|
||||
'guineafowl' => 3,
|
||||
'chicken' => 4,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Optionnal labels definition.
|
||||
* Enum labels
|
||||
*
|
||||
* @phpstan-ignore-next-line
|
||||
* @return array
|
||||
*/
|
||||
private const LABELS = [
|
||||
self::duck->name => 'Canard',
|
||||
self::turkey->name => 'Dinde',
|
||||
self::rabbit->name => 'Lapin',
|
||||
self::guineafowl->name => 'Pintade',
|
||||
self::chicken->name => 'Poulet',
|
||||
];
|
||||
protected static function labels(): array
|
||||
{
|
||||
return [
|
||||
'duck' => trans('Canard'),
|
||||
'turkey' => trans('Dinde'),
|
||||
'rabbit' => trans('Lapin'),
|
||||
'guineafowl' => trans('Pintade'),
|
||||
'chicken' => trans('Poulet'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,30 +2,52 @@
|
|||
|
||||
namespace App\Enums;
|
||||
|
||||
use App\Traits\Enums\BaseEnum;
|
||||
use Kwaadpepper\Enum\BaseEnum;
|
||||
|
||||
enum NutriscoreEnum: int
|
||||
/**
|
||||
* @method static self noLetter()
|
||||
* @method static self aLetter()
|
||||
* @method static self bLetter()
|
||||
* @method static self cLetter()
|
||||
* @method static self dLetter()
|
||||
* @method static self eLetter()
|
||||
*/
|
||||
final class NutriscoreEnum extends BaseEnum
|
||||
{
|
||||
use BaseEnum;
|
||||
|
||||
case noLetter = 0;
|
||||
case aLetter = 1;
|
||||
case bLetter = 2;
|
||||
case cLetter = 3;
|
||||
case dLetter = 4;
|
||||
case eLetter = 5;
|
||||
// @phpcs:ignore Generic.Commenting.Fixme.TaskFound
|
||||
// FIXME: faire en sorte de ne pas afficher le nutriscore en front si sa valeur est de 0.
|
||||
|
||||
/**
|
||||
* Optionnal labels definition.
|
||||
* Enum values
|
||||
*
|
||||
* @phpstan-ignore-next-line
|
||||
* @return array
|
||||
*/
|
||||
private const LABELS = [
|
||||
self::noLetter->name => 'Ø',
|
||||
self::aLetter->name => 'A',
|
||||
self::bLetter->name => 'B',
|
||||
self::cLetter->name => 'C',
|
||||
self::dLetter->name => 'D',
|
||||
self::eLetter->name => 'E'
|
||||
];
|
||||
protected static function values(): array
|
||||
{
|
||||
return [
|
||||
'noLetter' => 0,
|
||||
'aLetter' => 1,
|
||||
'bLetter' => 2,
|
||||
'cLetter' => 3,
|
||||
'dLetter' => 4,
|
||||
'eLetter' => 5
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Enum labels
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected static function labels(): array
|
||||
{
|
||||
return [
|
||||
'noLetter' => 'Ø',
|
||||
'aLetter' => 'A',
|
||||
'bLetter' => 'B',
|
||||
'cLetter' => 'C',
|
||||
'dLetter' => 'D',
|
||||
'eLetter' => 'E'
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,16 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Enums\Pagination;
|
||||
|
||||
use App\Traits\Enums\BaseEnum;
|
||||
|
||||
enum ItemsPerPaginationEnum: int
|
||||
{
|
||||
use BaseEnum;
|
||||
|
||||
case five = 5;
|
||||
case twelve = 12;
|
||||
case twentyfive = 25;
|
||||
case fifty = 50;
|
||||
case onehundred = 100;
|
||||
}
|
||||
|
|
@ -2,42 +2,64 @@
|
|||
|
||||
namespace App\Enums\Products;
|
||||
|
||||
use App\Traits\Enums\BaseEnum;
|
||||
use Kwaadpepper\Enum\BaseEnum;
|
||||
|
||||
enum ProductSpeciesEnum: int
|
||||
/**
|
||||
* @method static self caille()
|
||||
* @method static self canard()
|
||||
* @method static self canette()
|
||||
* @method static self coq()
|
||||
* @method static self coquelet()
|
||||
* @method static self dinde()
|
||||
* @method static self lapin()
|
||||
* @method static self pigeonneau()
|
||||
* @method static self pintade()
|
||||
* @method static self poule()
|
||||
* @method static self poulet()
|
||||
*/
|
||||
final class ProductSpeciesEnum extends BaseEnum
|
||||
{
|
||||
use BaseEnum;
|
||||
|
||||
case caille = 0;
|
||||
case canard = 1;
|
||||
case canette = 2;
|
||||
case coq = 3;
|
||||
case coquelet = 4;
|
||||
case dinde = 5;
|
||||
case lapin = 6;
|
||||
case pigeonneau = 7;
|
||||
case pintade = 8;
|
||||
case poule = 9;
|
||||
case poulet = 10;
|
||||
case volaille_festive = 11;
|
||||
/**
|
||||
* Enum values
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected static function values(): array
|
||||
{
|
||||
return [
|
||||
'caille' => 0,
|
||||
'canard' => 1,
|
||||
'canette' => 2,
|
||||
'coq' => 3,
|
||||
'coquelet' => 4,
|
||||
'dinde' => 5,
|
||||
'lapin' => 6,
|
||||
'pigeonneau' => 7,
|
||||
'pintade' => 8,
|
||||
'poule' => 9,
|
||||
'poulet' => 10,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Optionnal labels definition.
|
||||
* Enum labels
|
||||
*
|
||||
* @phpstan-ignore-next-line
|
||||
* @return array
|
||||
*/
|
||||
private const LABELS = [
|
||||
self::caille->name => 'Caille',
|
||||
self::canard->name => 'Canard',
|
||||
self::canette->name => 'Canette',
|
||||
self::coq->name => 'Coq',
|
||||
self::coquelet->name => 'Coquelet',
|
||||
self::dinde->name => 'Dinde',
|
||||
self::lapin->name => 'Lapin',
|
||||
self::pigeonneau->name => 'Pigeonneau',
|
||||
self::pintade->name => 'Pintade',
|
||||
self::poule->name => 'Poule',
|
||||
self::poulet->name => 'Poulet',
|
||||
self::volaille_festive->name => 'Volaille festive'
|
||||
];
|
||||
protected static function labels(): array
|
||||
{
|
||||
return [
|
||||
'caille' => trans('Caille'),
|
||||
'canard' => trans('Canard'),
|
||||
'canette' => trans('Canette'),
|
||||
'coq' => trans('Coq'),
|
||||
'coquelet' => trans('Coquelet'),
|
||||
'dinde' => trans('Dinde'),
|
||||
'lapin' => trans('Lapin'),
|
||||
'pigeonneau' => trans('Pigeonneau'),
|
||||
'pintade' => trans('Pintade'),
|
||||
'poule' => trans('Poule'),
|
||||
'poulet' => trans('Poulet')
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,37 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
use App\Traits\Enums\BaseEnum;
|
||||
|
||||
enum StaticPageType: int
|
||||
{
|
||||
use BaseEnum;
|
||||
|
||||
case contact = 1;
|
||||
case legals = 2;
|
||||
case confidentiality = 3;
|
||||
case expertise_guineafowl = 4;
|
||||
case expertise_turkey = 5;
|
||||
case expertise_chicken = 6;
|
||||
case expertise_duck = 7;
|
||||
case expertise_rabbit = 8;
|
||||
case sitemap = 9;
|
||||
|
||||
/**
|
||||
* Optionnal labels definition.
|
||||
*
|
||||
* @phpstan-ignore-next-line
|
||||
*/
|
||||
private const LABELS = [
|
||||
self::contact->name => 'Contact',
|
||||
self::legals->name => 'Mentions légales',
|
||||
self::confidentiality->name => 'Confidentialité',
|
||||
self::expertise_guineafowl->name => 'Expertise pintade',
|
||||
self::expertise_turkey->name => 'Expertise dinde',
|
||||
self::expertise_chicken->name => 'Expertise poulet',
|
||||
self::expertise_duck->name => 'Expertise canard',
|
||||
self::expertise_rabbit->name => 'Expertise lapin',
|
||||
self::sitemap->name => 'Plan du site',
|
||||
];
|
||||
}
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
use App\Traits\Enums\BaseEnum;
|
||||
|
||||
enum TagTypeEnum: int
|
||||
{
|
||||
use BaseEnum;
|
||||
|
||||
case recipes = 1;
|
||||
case products = 2;
|
||||
|
||||
/**
|
||||
* Optionnal labels definition.
|
||||
*
|
||||
* @phpstan-ignore-next-line
|
||||
*/
|
||||
private const LABELS = [
|
||||
self::recipes->name => 'Recettes / Astuces',
|
||||
self::products->name => 'Produits',
|
||||
];
|
||||
}
|
||||
|
|
@ -3,26 +3,18 @@
|
|||
namespace App\Exceptions;
|
||||
|
||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||
use Throwable;
|
||||
|
||||
class Handler extends ExceptionHandler
|
||||
{
|
||||
/**
|
||||
* A list of exception types with their corresponding custom log levels.
|
||||
*
|
||||
* @var array<class-string<\Throwable>, \Psr\Log\LogLevel::*>
|
||||
*/
|
||||
protected $levels = [];
|
||||
|
||||
/**
|
||||
* A list of the exception types that are not reported.
|
||||
*
|
||||
* @var array<int, class-string<\Throwable>>
|
||||
* @var array<int, class-string<Throwable>>
|
||||
*/
|
||||
protected $dontReport = [];
|
||||
|
||||
/**
|
||||
* A list of the inputs that are never flashed to the session on validation exceptions.
|
||||
* A list of the inputs that are never flashed for validation exceptions.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
|
|
@ -39,7 +31,7 @@ class Handler extends ExceptionHandler
|
|||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->reportable(function (Throwable $e) {
|
||||
$this->reportable(function (\Throwable $e) {
|
||||
if (app()->bound('sentry')) {
|
||||
app('sentry')->captureException($e);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,142 +3,134 @@
|
|||
namespace App\Http\Controllers\Bo;
|
||||
|
||||
use App\Enums\Advices\AdviceTypeEnum;
|
||||
use App\Enums\TagTypeEnum;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Bo\Advice\StoreAdviceRequest;
|
||||
use App\Http\Requests\Bo\Advice\UpdateAdviceRequest;
|
||||
use App\Models\Advice;
|
||||
use App\Models\Product;
|
||||
use App\Models\Tag;
|
||||
use App\Traits\Controllers\ManagesOrder;
|
||||
use App\Traits\Controllers\UpdateModelPublished;
|
||||
use Illuminate\Contracts\Database\Eloquent\Builder;
|
||||
use App\Traits\Controllers\UpdateModelStatus;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class AdviceController extends Controller
|
||||
{
|
||||
use UpdateModelPublished;
|
||||
use ManagesOrder;
|
||||
use UpdateModelStatus;
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \App\Enums\Advices\AdviceTypeEnum|null $type
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index(Request $request, AdviceTypeEnum|null $type = null): \Illuminate\Contracts\View\View
|
||||
public function index(Request $request)
|
||||
{
|
||||
$type = $type ?: AdviceTypeEnum::all;
|
||||
/** @var \Illuminate\Database\Eloquent\Builder $adviceModels */
|
||||
$adviceModels = Advice::query();
|
||||
/** @var \Illuminate\Database\Eloquent\Builder $advice */
|
||||
$advice = Advice::query();
|
||||
$type = $request->type;
|
||||
$currentType = AdviceTypeEnum::make(\intval($type));
|
||||
|
||||
$adviceModels->when(!$type->equals(AdviceTypeEnum::all), fn (Builder $q) => $q->where('type', $type));
|
||||
$advice->when(isset($type), function ($advice) use ($currentType) {
|
||||
$advice->where('type', '=', $currentType->value);
|
||||
});
|
||||
|
||||
/** @var string|null $search Search field */
|
||||
$search = $request->input('search');
|
||||
if ($search) {
|
||||
if ($request->search) {
|
||||
$this->searchQuery(
|
||||
$adviceModels,
|
||||
$search,
|
||||
$advice,
|
||||
$request->search,
|
||||
null,
|
||||
'title'
|
||||
);
|
||||
}
|
||||
|
||||
$this->sortQuery($advice);
|
||||
$searchFields = trans('Titre');
|
||||
|
||||
/** Sort columns with a query */
|
||||
$this->sortQuery($adviceModels);
|
||||
$advice = $advice->paginate(10);
|
||||
|
||||
/** Custom pagination */
|
||||
$adviceModels = $this->paginate($adviceModels);
|
||||
|
||||
return view('bo.pages.advice.index', [
|
||||
'adviceModels' => $adviceModels,
|
||||
'currentType' => $type,
|
||||
'search' => $search,
|
||||
'searchFields' => $searchFields
|
||||
]);
|
||||
return view('bo.pages.advice.index', compact('advice', 'currentType', 'searchFields'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @param \App\Enums\Advices\AdviceTypeEnum $type
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create(AdviceTypeEnum $type): \Illuminate\Contracts\View\View
|
||||
public function create(Request $request)
|
||||
{
|
||||
$advice = new Advice();
|
||||
$adviceTags = Tag::query()->where('type', TagTypeEnum::recipes)->select(['id', 'label', 'slug'])->get();
|
||||
$type = $request->type;
|
||||
$currentType = AdviceTypeEnum::make(\intval($type));
|
||||
$adviceTags = Tag::query()->select(['id', 'label', 'slug'])->get();
|
||||
$adviceProducts = Product::all();
|
||||
$recipeList = Advice::query()->where('type', '=', AdviceTypeEnum::recipes)->get();
|
||||
$tipList = Advice::query()->where('type', '=', AdviceTypeEnum::tips)->get();
|
||||
$recipeList = Advice::where('type', '=', AdviceTypeEnum::recipes())->get();
|
||||
$tipList = Advice::where('type', '=', AdviceTypeEnum::tips())->get();
|
||||
|
||||
$recipeList = collect($recipeList)->each(function (\App\Models\Advice &$value) {
|
||||
$value->label = $value->title;
|
||||
});
|
||||
$tipList = collect($tipList)->each(function (\App\Models\Advice &$value) {
|
||||
$value->label = $value->title;
|
||||
});
|
||||
|
||||
$recipesSelected = collect();
|
||||
$tipsSelected = collect();
|
||||
collect($advice->advices)
|
||||
// @phpstan-ignore-next-line
|
||||
->each(function (Advice $eltAdvice) use (&$recipesSelected, &$tipsSelected) {
|
||||
if ($eltAdvice->type->equals(AdviceTypeEnum::recipes)) {
|
||||
$recipesSelected = $recipesSelected->concat([$eltAdvice]);
|
||||
} elseif ($eltAdvice->type->equals(AdviceTypeEnum::tips)) {
|
||||
$tipsSelected = $tipsSelected->concat([$eltAdvice]);
|
||||
}
|
||||
});
|
||||
$recipesSelected = collect([]);
|
||||
$tipsSelected = collect([]);
|
||||
collect($advice->advices)->each(function ($eltAdvice) use (&$recipesSelected, &$tipsSelected) {
|
||||
if ($eltAdvice->type->value == AdviceTypeEnum::recipes()->value) {
|
||||
$eltAdvice->label = $eltAdvice->title;
|
||||
$recipesSelected = $recipesSelected->concat([$eltAdvice]);
|
||||
} elseif ($eltAdvice->type->value == AdviceTypeEnum::tips()->value) {
|
||||
$eltAdvice->label = $eltAdvice->title;
|
||||
$tipsSelected = $tipsSelected->concat([$eltAdvice]);
|
||||
}
|
||||
});
|
||||
|
||||
return view('bo.pages.advice.create', [
|
||||
'adviceModel' => $advice,
|
||||
'currentType' => $type,
|
||||
'adviceTags' => $adviceTags,
|
||||
'adviceProducts' => $adviceProducts,
|
||||
'recipeList' => $recipeList,
|
||||
'tipList' => $tipList,
|
||||
'advice' => $advice,
|
||||
'currentType' => $currentType,
|
||||
'adviceTags' => $adviceTags,
|
||||
'adviceProducts' => $adviceProducts,
|
||||
'recipeList' => $recipeList,
|
||||
'tipList' => $tipList,
|
||||
'recipesSelected' => $recipesSelected,
|
||||
'tipsSelected' => $tipsSelected,
|
||||
'tipsSelected' => $tipsSelected,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \App\Http\Requests\Bo\Advice\StoreAdviceRequest $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @param \App\Http\Requests\Bo\Advice\StoreAdviceRequest $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(StoreAdviceRequest $request): \Illuminate\Http\RedirectResponse
|
||||
public function store(StoreAdviceRequest $request)
|
||||
{
|
||||
return DB::transaction(function () use ($request) {
|
||||
$advice = new Advice();
|
||||
$advice->fill(Arr::except($request->validated(), [
|
||||
'tags',
|
||||
'products',
|
||||
'associated_tips_list',
|
||||
'associated_recipes_list',
|
||||
]));
|
||||
$advice->fill($request->validated());
|
||||
|
||||
$currentType = AdviceTypeEnum::make(\intval($request->type));
|
||||
|
||||
if ($advice->saveOrFail()) {
|
||||
$advice->tags()->sync(collect($request->input('tags'))->pluck('id'));
|
||||
$advice->products()->sync($request->input('products_list'));
|
||||
$advice->advices()->sync(array_merge($request->input('recipes_list'), $request->input('tips_list')));
|
||||
$advice->tags()->sync(collect($request->tags)->pluck('id'));
|
||||
$advice->products()->sync($request->products_list);
|
||||
$advice->advices()->sync(array_merge($request->recipes_list, $request->tips_list));
|
||||
|
||||
return redirect()
|
||||
->route('bo.advice.edit', $advice)
|
||||
->with('success', __(
|
||||
'crud.messages.has_been_created',
|
||||
['model' => Str::singular($currentType->label())]
|
||||
->with('success', trans(
|
||||
':model a été créé',
|
||||
['model' => Str::singular($currentType->label)]
|
||||
));
|
||||
}
|
||||
|
||||
return redirect()
|
||||
->back()
|
||||
->with('error', __(
|
||||
'crud.messages.cannot_be_created',
|
||||
['model' => Str::singular($currentType->label())]
|
||||
->with('error', trans(
|
||||
':model n\'a pas été créé',
|
||||
['model' => Str::singular($currentType->label)]
|
||||
));
|
||||
});
|
||||
}
|
||||
|
|
@ -147,55 +139,69 @@ class AdviceController extends Controller
|
|||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\Models\Advice $advice
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit(Advice $advice): \Illuminate\Contracts\View\View
|
||||
public function edit(Advice $advice)
|
||||
{
|
||||
$currentType = $advice->type;
|
||||
$adviceTags = Tag::query()->where('type', TagTypeEnum::recipes)
|
||||
$adviceTags = Tag::whereNotIn('id', $advice->tags()->pluck('id'))
|
||||
->select(['id', 'label', 'slug'])->get();
|
||||
$adviceProducts = Product::all();
|
||||
$recipeList = Advice::query()->where([
|
||||
['type', '=', AdviceTypeEnum::recipes],
|
||||
$recipeList = Advice::where([
|
||||
['type', '=', AdviceTypeEnum::recipes()],
|
||||
['id', '!=', $advice->id],
|
||||
])->get();
|
||||
$tipList = Advice::query()->where([
|
||||
['type', '=', AdviceTypeEnum::tips],
|
||||
$tipList = Advice::where([
|
||||
['type', '=', AdviceTypeEnum::tips()],
|
||||
['id', '!=', $advice->id],
|
||||
])->get();
|
||||
|
||||
$recipeList = collect($recipeList)->each(function (\App\Models\Advice &$value) {
|
||||
$value->label = $value->title;
|
||||
});
|
||||
$tipList = collect($tipList)->each(function (\App\Models\Advice &$value) {
|
||||
$value->label = $value->title;
|
||||
});
|
||||
|
||||
$recipesSelected = collect([]);
|
||||
$tipsSelected = collect([]);
|
||||
|
||||
/** @var \Illuminate\Database\Eloquent\Collection<\App\Models\Advice> */
|
||||
$recipesSelected = $advice->recipes()->each(function (Advice &$recipe) {
|
||||
$recipe->label = $recipe->title;
|
||||
});
|
||||
/** @var \Illuminate\Database\Eloquent\Collection<\App\Models\Advice> */
|
||||
$tipsSelected = $advice->tips()->each(function (Advice &$tip) {
|
||||
$tip->label = $tip->title;
|
||||
});
|
||||
|
||||
return view('bo.pages.advice.edit', [
|
||||
'adviceModel' => $advice,
|
||||
'currentType' => $currentType,
|
||||
'adviceTags' => $adviceTags,
|
||||
'adviceProducts' => $adviceProducts,
|
||||
'recipeList' => $recipeList,
|
||||
'tipList' => $tipList,
|
||||
'recipesSelected' => $advice->recipes,
|
||||
'tipsSelected' => $advice->tips,
|
||||
'advice' => $advice,
|
||||
'currentType' => $currentType,
|
||||
'adviceTags' => $adviceTags,
|
||||
'adviceProducts' => $adviceProducts,
|
||||
'recipeList' => $recipeList,
|
||||
'tipList' => $tipList,
|
||||
'recipesSelected' => $recipesSelected,
|
||||
'tipsSelected' => $tipsSelected,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \App\Http\Requests\Bo\Advice\UpdateAdviceRequest $request
|
||||
* @param \App\Models\Advice $advice
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @param \App\Http\Requests\Bo\Advice\UpdateAdviceRequest $request
|
||||
* @param \App\Models\Advice $advice
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(UpdateAdviceRequest $request, Advice $advice): \Illuminate\Http\RedirectResponse
|
||||
public function update(UpdateAdviceRequest $request, Advice $advice)
|
||||
{
|
||||
return DB::transaction(function () use ($request, $advice) {
|
||||
$advice->tags()->sync(collect($request->input('tags'))->pluck('id'));
|
||||
$advice->products()->sync($request->input('products_list'));
|
||||
$advice->advices()->sync(array_merge($request->input('recipes_list'), $request->input('tips_list')));
|
||||
$advice->tags()->sync(collect($request->tags)->pluck('id'));
|
||||
$advice->products()->sync($request->products_list);
|
||||
$advice->advices()->sync(array_merge($request->recipes_list, $request->tips_list));
|
||||
|
||||
$advice->fill(Arr::except($request->validated(), [
|
||||
'tags',
|
||||
'products',
|
||||
'associated_tips_list',
|
||||
'associated_recipes_list',
|
||||
]));
|
||||
$advice->fill($request->validated());
|
||||
|
||||
$currentType = AdviceTypeEnum::make(\intval($request->type));
|
||||
|
||||
|
|
@ -203,16 +209,16 @@ class AdviceController extends Controller
|
|||
return redirect()
|
||||
->route('bo.advice.edit', $advice)
|
||||
->with('success', trans(
|
||||
'crud.messages.has_been_updated',
|
||||
['model' => Str::singular($currentType->label())]
|
||||
':model a été mis à jour',
|
||||
['model' => Str::singular($currentType->label)]
|
||||
));
|
||||
}
|
||||
|
||||
return redirect()
|
||||
->back()
|
||||
->with('error', trans(
|
||||
'crud.messages.cannot_be_updated',
|
||||
['model' => Str::singular($currentType->label())]
|
||||
':model n\'a pas été mis à jour',
|
||||
['model' => Str::singular($currentType->label)]
|
||||
));
|
||||
});
|
||||
}
|
||||
|
|
@ -220,32 +226,32 @@ class AdviceController extends Controller
|
|||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\Advice $advice
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @param \App\Models\Advice $advice
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy(Advice $advice): \Illuminate\Http\RedirectResponse
|
||||
public function destroy(Advice $advice)
|
||||
{
|
||||
DB::table('advice_advice')->where($advice->advices()->getRelatedPivotKeyName(), $advice->id)->delete();
|
||||
$advice->tags()->sync([]);
|
||||
$advice->products()->sync([]);
|
||||
$advice->advices()->sync([]);
|
||||
|
||||
$currentType = AdviceTypeEnum::make(\intval($advice->type->value()));
|
||||
$currentType = AdviceTypeEnum::make(\intval($advice->type->value));
|
||||
|
||||
if ($advice->deleteOrFail()) {
|
||||
return redirect()
|
||||
->route('bo.advice.index', ['type' => $currentType])
|
||||
->with('warning', trans(
|
||||
'crud.messages.has_been_deleted',
|
||||
['model' => Str::singular($currentType->label())]
|
||||
':model a bien été supprimé',
|
||||
['model' => Str::singular($currentType->label)]
|
||||
));
|
||||
}
|
||||
|
||||
return redirect()
|
||||
->back()
|
||||
->with('error', trans(
|
||||
'crud.messages.cannot_be_deleted',
|
||||
['model' => Str::singular($currentType->label())]
|
||||
':model n\'a pas été supprimé',
|
||||
['model' => Str::singular($currentType->label)]
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,14 +3,24 @@
|
|||
namespace App\Http\Controllers\Bo\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Contracts\Auth\StatefulGuard;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Illuminate\Foundation\Auth\AuthenticatesUsers;
|
||||
use Illuminate\Foundation\Auth\ThrottlesLogins;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
|
||||
class LoginController extends Controller
|
||||
{
|
||||
use AuthenticatesUsers;
|
||||
use ThrottlesLogins;
|
||||
|
||||
/**
|
||||
* Where to redirect users after login.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $redirectTo = RouteServiceProvider::HOME;
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
|
|
@ -22,33 +32,68 @@ class LoginController extends Controller
|
|||
$this->middleware('guest:backend')->except('logout');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the guard to be used during authentication.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Auth\StatefulGuard
|
||||
*/
|
||||
protected function guard(): StatefulGuard
|
||||
{
|
||||
return Auth::guard('backend');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the application's login form.
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showLoginForm(): View
|
||||
public function showLoginForm()
|
||||
{
|
||||
return view('bo.auth.login');
|
||||
}
|
||||
|
||||
/**
|
||||
* Where to redirect users after login.
|
||||
* Attempt to log the user into the application.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return boolean
|
||||
*/
|
||||
protected function attemptLogin(Request $request)
|
||||
{
|
||||
return Auth::guard('backend')->attempt(
|
||||
$this->credentials($request),
|
||||
$request->filled('remember')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* The user has been authenticated.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param null $user
|
||||
* @return mixed
|
||||
* @phpcs:disable Squiz.Commenting.FunctionComment.TypeHintMissing, Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
|
||||
*/
|
||||
protected function authenticated(Request $request, $user)
|
||||
{
|
||||
/** @var \App\Models\User|null */
|
||||
$user = Auth::guard('backend')->user();
|
||||
if ($user) {
|
||||
$user->last_connection = now();
|
||||
$user->saveOrFail();
|
||||
Session::flash('info', trans('Vous êtes à présent connecté'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The user has logged out of the application.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return mixed
|
||||
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
|
||||
*/
|
||||
protected function loggedOut(Request $request)
|
||||
{
|
||||
Session::flash('info', trans('Vous êtes à présent déconnecté'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the post register / login redirect path.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function redirectTo(): string
|
||||
public function redirectPath()
|
||||
{
|
||||
return response()->redirectToIntended()->getTargetUrl();
|
||||
return response()->redirectToRoute('bo.dashboard')->getTargetUrl();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,152 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Bo;
|
||||
|
||||
use App\Http\Requests\Bo\BrigadeSections\StoreBrigadeSectionsRequest;
|
||||
use App\Http\Requests\Bo\BrigadeSections\UpdateBrigadeSectionsRequest;
|
||||
use App\Models\BrigadeSection;
|
||||
use App\Traits\Controllers\ChangesModelOrder;
|
||||
use App\Traits\Controllers\UpdateModelPublished;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Uwil\Laravel\Common\Controllers\Controller;
|
||||
|
||||
class BrigadeSectionController extends Controller
|
||||
{
|
||||
use UpdateModelPublished;
|
||||
use ChangesModelOrder;
|
||||
|
||||
/**
|
||||
* 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 $brigadeSectionModels */
|
||||
$brigadeSectionModels = BrigadeSection::query();
|
||||
|
||||
/** @var string $search Search field */
|
||||
$search = $request->search;
|
||||
if ($search) {
|
||||
$this->searchQuery(
|
||||
$brigadeSectionModels,
|
||||
$search,
|
||||
null,
|
||||
'title',
|
||||
'content',
|
||||
'button_text',
|
||||
'button_url'
|
||||
);
|
||||
}
|
||||
$searchFields = trans('Titre, Texte, CTA, Lien');
|
||||
|
||||
/** Sort columns with a query */
|
||||
$this->sortQuery($brigadeSectionModels);
|
||||
|
||||
/** Custom pagination */
|
||||
$brigadeSectionModels = $this->paginate($brigadeSectionModels);
|
||||
|
||||
return view('bo.pages.brigade_sections.index', compact('brigadeSectionModels', 'searchFields'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @param \App\Models\BrigadeSection $brigadeSection
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function create(BrigadeSection $brigadeSection): \Illuminate\Contracts\View\View
|
||||
{
|
||||
$brigadeSection = $brigadeSection->exists() ? $brigadeSection : new BrigadeSection();
|
||||
|
||||
return view('bo.pages.brigade_sections.create', [
|
||||
'brigadeSectionModel' => $brigadeSection,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \App\Http\Requests\Bo\BrigadeSections\StoreBrigadeSectionsRequest $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function store(StoreBrigadeSectionsRequest $request): \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
return DB::transaction(function () use ($request) {
|
||||
$brigadeSection = new BrigadeSection();
|
||||
$brigadeSection->fill($request->validated());
|
||||
|
||||
if ($brigadeSection->saveOrFail()) {
|
||||
return redirect()->route('bo.brigade_sections.edit', $brigadeSection->id)
|
||||
->with('success', __('crud.messages.has_been_created', [
|
||||
'model' => trans_choice('models.classes.brigade_section', 1)
|
||||
]));
|
||||
}
|
||||
return redirect()->back()
|
||||
->with('error', __('crud.messages.cannot_be_created', [
|
||||
'model' => trans_choice('models.classes.brigade_section', 1)
|
||||
]));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\Models\BrigadeSection $brigadeSection
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function edit(BrigadeSection $brigadeSection): \Illuminate\Contracts\View\View
|
||||
{
|
||||
return view('bo.pages.brigade_sections.edit', [
|
||||
'brigadeSectionModel' => $brigadeSection,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \App\Http\Requests\Bo\BrigadeSections\UpdateBrigadeSectionsRequest $request
|
||||
* @param \App\Models\BrigadeSection $brigadeSection
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update(UpdateBrigadeSectionsRequest $request, BrigadeSection $brigadeSection): RedirectResponse
|
||||
{
|
||||
return DB::transaction(function () use ($request, $brigadeSection) {
|
||||
$brigadeSection->fill($request->validated());
|
||||
|
||||
if ($brigadeSection->saveOrFail()) {
|
||||
return redirect()->route('bo.brigade_sections.edit', $brigadeSection->id)
|
||||
->with('success', __('crud.messages.has_been_updated', [
|
||||
'model' => trans_choice('models.classes.brigade_section', 1)
|
||||
]));
|
||||
}
|
||||
return redirect()->route('bo.brigade_sections.edit', $brigadeSection->id)
|
||||
->with('error', __('crud.messages.cannot_be_updated', [
|
||||
'model' => trans_choice('models.classes.brigade_section', 1)
|
||||
]));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\BrigadeSection $brigadeSection
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy(BrigadeSection $brigadeSection): \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
if ($brigadeSection->deleteOrFail()) {
|
||||
return redirect()->route('bo.brigade_sections.index')
|
||||
->with('success', __('crud.messages.has_been_deleted', [
|
||||
'model' => trans_choice('models.classes.brigade_section', 1)
|
||||
]));
|
||||
}
|
||||
return redirect()->back()
|
||||
->with('error', __('crud.messages.cannot_be_deleted', [
|
||||
'model' => trans_choice('models.classes.brigade_section', 1)
|
||||
]));
|
||||
}
|
||||
}
|
||||
|
|
@ -16,68 +16,62 @@ class ExpertiseProductController extends Controller
|
|||
* Display a listing of the resource.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index(Request $request): \Illuminate\Contracts\View\View
|
||||
public function index(Request $request)
|
||||
{
|
||||
/** @var \Illuminate\Database\Eloquent\Builder $vipModels */
|
||||
$vipModels = ExpertiseProduct::query();
|
||||
/** @var \Illuminate\Database\Eloquent\Builder $vips */
|
||||
$vips = ExpertiseProduct::query();
|
||||
|
||||
/** @var string $search Search field */
|
||||
$search = $request->search;
|
||||
if ($search) {
|
||||
if ($request->search) {
|
||||
$this->searchQuery(
|
||||
$vipModels,
|
||||
$search,
|
||||
$vips,
|
||||
$request->search,
|
||||
null,
|
||||
'label',
|
||||
'title'
|
||||
);
|
||||
}
|
||||
|
||||
$this->sortQuery($vips);
|
||||
$searchFields = trans('Libellé, Titre');
|
||||
|
||||
/** Sort columns with a query */
|
||||
$this->sortQuery($vipModels);
|
||||
$vips = $vips->paginate(10);
|
||||
|
||||
/** Custom pagination */
|
||||
$vipModels = $this->paginate($vipModels);
|
||||
|
||||
return view('bo.pages.vips.index', compact('vipModels', 'search', 'searchFields'));
|
||||
return view('bo.pages.vips.index', compact('vips', 'searchFields'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @param \App\Models\ExpertiseProduct $vip
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create(ExpertiseProduct $vip): \Illuminate\Contracts\View\View
|
||||
public function create()
|
||||
{
|
||||
return view('bo.pages.vips.create', ['vipModel' => $vip]);
|
||||
return view('bo.pages.vips.create');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \App\Http\Requests\Bo\ExpertiseProducts\StoreExpertiseProductRequest $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @param \App\Http\Requests\Bo\ExpertiseProducts\StoreExpertiseProductRequest $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(StoreExpertiseProductRequest $request): \Illuminate\Http\RedirectResponse
|
||||
public function store(StoreExpertiseProductRequest $request)
|
||||
{
|
||||
return DB::transaction(function () use ($request) {
|
||||
$vip = new ExpertiseProduct();
|
||||
$vip->fill($request->validated());
|
||||
|
||||
if ($vip->saveOrFail()) {
|
||||
return redirect()->route('bo.vips.edit', $vip->id)
|
||||
->with('success', __('crud.messages.has_been_created', [
|
||||
'model' => Str::singular(trans_choice('models.classes.vips', 2))
|
||||
]));
|
||||
return redirect()
|
||||
->route('bo.vips.edit', $vip)
|
||||
->with('success', trans(
|
||||
':model a été créé',
|
||||
['model' => Str::singular(trans('models.classes.vips'))]
|
||||
));
|
||||
}
|
||||
return redirect()->back()
|
||||
->with('error', __('crud.messages.cannot_be_created', [
|
||||
'model' => Str::singular(trans_choice('models.classes.vips', 2))
|
||||
]));
|
||||
return back();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -85,57 +79,55 @@ class ExpertiseProductController extends Controller
|
|||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\Models\ExpertiseProduct $vip
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit(ExpertiseProduct $vip): \Illuminate\Contracts\View\View
|
||||
public function edit(ExpertiseProduct $vip)
|
||||
{
|
||||
return view('bo.pages.vips.edit', ['vipModel' => $vip]);
|
||||
return view('bo.pages.vips.edit', [
|
||||
'vip' => $vip
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \App\Http\Requests\Bo\ExpertiseProducts\UpdateExpertiseProductRequest $request
|
||||
* @param \App\Models\ExpertiseProduct $vip
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @param \App\Http\Requests\Bo\ExpertiseProduct\UpdateExpertiseProductRequest $request
|
||||
* @param \App\Models\ExpertiseProduct $vip
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(
|
||||
UpdateExpertiseProductRequest $request,
|
||||
ExpertiseProduct $vip
|
||||
): \Illuminate\Http\RedirectResponse {
|
||||
public function update(UpdateExpertiseProductRequest $request, ExpertiseProduct $vip)
|
||||
{
|
||||
return DB::transaction(function () use ($request, $vip) {
|
||||
$vip->fill($request->validated());
|
||||
|
||||
if ($vip->saveOrFail()) {
|
||||
return redirect()->route('bo.vips.edit', $vip->id)
|
||||
->with('success', __('crud.messages.has_been_updated', [
|
||||
'model' => Str::singular(trans_choice('models.classes.vips', 2))
|
||||
]));
|
||||
return redirect()
|
||||
->route('bo.vips.edit', $vip)
|
||||
->with('success', trans(
|
||||
':model a été mis à jour',
|
||||
['model' => Str::singular(trans('models.classes.vips'))]
|
||||
));
|
||||
}
|
||||
return redirect()->route('bo.vips.edit', $vip->id)
|
||||
->with('error', __('crud.messages.cannot_be_updated', [
|
||||
'model' => Str::singular(trans_choice('models.classes.vips', 2))
|
||||
]));
|
||||
return back();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\ExpertiseProduct $vip
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @param \App\Models\ExpertiseProduct $vip
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy(ExpertiseProduct $vip): \Illuminate\Http\RedirectResponse
|
||||
public function destroy(ExpertiseProduct $vip)
|
||||
{
|
||||
if ($vip->deleteOrFail()) {
|
||||
return redirect()->route('bo.vips.index')
|
||||
->with('success', __('crud.messages.has_been_deleted', [
|
||||
'model' => Str::singular(trans_choice('models.classes.vips', 2))
|
||||
]));
|
||||
return redirect()
|
||||
->route('bo.vips.index')
|
||||
->with('warning', trans(
|
||||
':model a bien été supprimé',
|
||||
['model' => Str::singular(trans('models.classes.vips'))]
|
||||
));
|
||||
}
|
||||
return redirect()->back()
|
||||
->with('error', __('crud.messages.cannot_be_deleted', [
|
||||
'model' => Str::singular(trans_choice('models.classes.vips', 2))
|
||||
]));
|
||||
return back();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,12 +7,12 @@ use App\Http\Controllers\Controller;
|
|||
class HomeController extends Controller
|
||||
{
|
||||
/**
|
||||
* Dashboard view.
|
||||
* Dashboard view
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
* @return \Illuminate\Contracts\View\View|\Illuminate\Contracts\View\Factory
|
||||
*/
|
||||
public function dashboard(): \Illuminate\Contracts\View\View
|
||||
public function dashboard()
|
||||
{
|
||||
return view('bo.pages.homepage');
|
||||
return view('bo.pages.home');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ namespace App\Http\Controllers\Bo;
|
|||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Bo\NewsCategories\UpdateNewsCategoryRequest;
|
||||
use App\Models\NewsCategory;
|
||||
use App\Traits\Controllers\ChangesModelOrder;
|
||||
use App\Traits\Models\ChangesModelOrder;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
|
@ -18,44 +18,40 @@ class NewsCategoryController extends Controller
|
|||
* Display a listing of the resource.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index(Request $request): \Illuminate\Contracts\View\View
|
||||
public function index(Request $request)
|
||||
{
|
||||
/** @var \Illuminate\Database\Eloquent\Builder $newscategoryModels */
|
||||
$newscategoryModels = NewsCategory::query();
|
||||
/** @var \Illuminate\Database\Eloquent\Builder $newscategories */
|
||||
$newscategories = NewsCategory::query();
|
||||
|
||||
/** @var string $search Search field */
|
||||
$search = $request->search;
|
||||
if ($search) {
|
||||
if ($request->search) {
|
||||
$this->searchQuery(
|
||||
$newscategoryModels,
|
||||
$search,
|
||||
$newscategories,
|
||||
$request->search,
|
||||
null,
|
||||
'label'
|
||||
);
|
||||
}
|
||||
|
||||
$this->sortQuery($newscategories);
|
||||
$searchFields = trans('Libellé');
|
||||
|
||||
/** Sort columns with a query */
|
||||
$this->sortQuery($newscategoryModels);
|
||||
$newscategories = $newscategories->get();
|
||||
|
||||
/** Custom pagination */
|
||||
$newscategoryModels = $this->paginate($newscategoryModels);
|
||||
|
||||
return view('bo.pages.newscategories.index', compact('newscategoryModels', 'searchFields'));
|
||||
return view('bo.pages.newscategories.index', compact('newscategories', 'searchFields'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\Models\NewsCategory $newscategory
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit(NewsCategory $newscategory): \Illuminate\Contracts\View\View
|
||||
public function edit(NewsCategory $newscategory)
|
||||
{
|
||||
return view('bo.pages.newscategories.edit', [
|
||||
'newscategoryModel' => $newscategory
|
||||
'newscategory' => $newscategory
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
@ -64,25 +60,22 @@ class NewsCategoryController extends Controller
|
|||
*
|
||||
* @param \App\Http\Requests\Bo\NewsCategories\UpdateNewsCategoryRequest $request
|
||||
* @param \App\Models\NewsCategory $newscategory
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(
|
||||
UpdateNewsCategoryRequest $request,
|
||||
NewsCategory $newscategory
|
||||
): \Illuminate\Http\RedirectResponse {
|
||||
public function update(UpdateNewsCategoryRequest $request, NewsCategory $newscategory)
|
||||
{
|
||||
return DB::transaction(function () use ($request, $newscategory) {
|
||||
$newscategory->fill($request->validated());
|
||||
|
||||
if ($newscategory->saveOrFail()) {
|
||||
return redirect()->route('bo.newscategories.edit', $newscategory->id)
|
||||
->with('success', __('crud.messages.has_been_created', [
|
||||
'model' => Str::singular(__('models.classes.newscategories'))
|
||||
]));
|
||||
return redirect()
|
||||
->route('bo.newscategories.edit', $newscategory)
|
||||
->with('success', trans(
|
||||
':model a été mis à jour',
|
||||
['model' => Str::singular(trans('models.classes.newscategories'))]
|
||||
));
|
||||
}
|
||||
return redirect()->back()
|
||||
->with('error', __('crud.messages.cannot_be_created', [
|
||||
'model' => Str::singular(__('models.classes.newscategories'))
|
||||
]));
|
||||
return redirect()->back();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,32 +8,30 @@ use App\Http\Requests\Bo\News\UpdateNewsRequest;
|
|||
use App\Models\News;
|
||||
use App\Models\NewsCategory;
|
||||
use App\Models\Product;
|
||||
use App\Traits\Controllers\UpdateModelPublished;
|
||||
use App\Traits\Controllers\UpdateModelStatus;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class NewsController extends Controller
|
||||
{
|
||||
use UpdateModelPublished;
|
||||
use UpdateModelStatus;
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index(Request $request): \Illuminate\Contracts\View\View
|
||||
public function index(Request $request)
|
||||
{
|
||||
/** @var \Illuminate\Database\Eloquent\Builder $newsModels */
|
||||
$newsModels = News::query();
|
||||
/** @var \Illuminate\Database\Eloquent\Builder $news */
|
||||
$news = News::query();
|
||||
|
||||
/** @var string $search Search field */
|
||||
$search = $request->search;
|
||||
if ($search) {
|
||||
if ($request->search) {
|
||||
$this->searchQuery(
|
||||
$newsModels,
|
||||
$search,
|
||||
$news,
|
||||
$request->search,
|
||||
null,
|
||||
'title',
|
||||
'subtitle',
|
||||
|
|
@ -41,74 +39,71 @@ class NewsController extends Controller
|
|||
'content2'
|
||||
);
|
||||
}
|
||||
|
||||
$this->sortQuery($news);
|
||||
$searchFields = trans('Titre, Sous-titre, Contenus');
|
||||
|
||||
/** Sort columns with a query */
|
||||
$this->sortQuery($newsModels);
|
||||
$news = $news->paginate(10);
|
||||
|
||||
/** Custom pagination */
|
||||
$newsModels = $this->paginate($newsModels);
|
||||
|
||||
return view('bo.pages.news.index', compact('newsModels', 'searchFields'));
|
||||
return view('bo.pages.news.index', compact('news', 'searchFields'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @param \App\Models\News $news
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create(News $news): \Illuminate\Contracts\View\View
|
||||
public function create()
|
||||
{
|
||||
$news = $news->exists() ? $news : new News();
|
||||
$news = new News();
|
||||
$newsCategories = NewsCategory::all();
|
||||
$newsProducts = Product::all();
|
||||
$newsList = News::all();
|
||||
|
||||
$newsList = collect($newsList)->each(function (News $value) {
|
||||
$value->setAttribute('label', $value->title);
|
||||
$newsList = collect($newsList)->each(function (\App\Models\News &$value) {
|
||||
$value->label = $value->title;
|
||||
});
|
||||
|
||||
$newsSelected = collect([]);
|
||||
collect($news->news ?? [])->each(function (News $value) use (&$newsSelected) {
|
||||
$value->setAttribute('label', $value->title);
|
||||
collect($news->news ?? [])->each(function (\App\Models\News &$value) use (&$newsSelected) {
|
||||
$value->label = $value->title;
|
||||
$newsSelected = $newsSelected->concat([$value]);
|
||||
});
|
||||
|
||||
return view('bo.pages.news.create', [
|
||||
'newsModel' => $news,
|
||||
'newsCategories' => $newsCategories,
|
||||
'newsProducts' => $newsProducts,
|
||||
'newsList' => $newsList,
|
||||
]);
|
||||
return view('bo.pages.news.create', compact('newsCategories', 'newsProducts', 'newsList'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \App\Http\Requests\Bo\News\StoreNewsRequest $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @param \App\Http\Requests\Bo\News\StoreNewsRequest $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(StoreNewsRequest $request): \Illuminate\Http\RedirectResponse
|
||||
public function store(StoreNewsRequest $request)
|
||||
{
|
||||
return DB::transaction(function () use ($request) {
|
||||
$news = new News();
|
||||
$news->fill($request->safe()->except(['categories', 'products', 'associated_news_list']));
|
||||
$news->fill($request->validated());
|
||||
|
||||
if ($news->saveOrFail()) {
|
||||
$news->categories()->sync($request->categories_list);
|
||||
$news->products()->sync($request->products_list);
|
||||
$news->news()->sync($request->news_list);
|
||||
|
||||
return redirect()->route('bo.news.edit', $news->id)
|
||||
->with('success', __('crud.messages.has_been_created', [
|
||||
'model' => Str::singular(__('models.classes.news'))
|
||||
]));
|
||||
return redirect()
|
||||
->route('bo.news.edit', $news)
|
||||
->with('success', trans(
|
||||
':model a été créé',
|
||||
['model' => Str::singular(trans('models.classes.news'))]
|
||||
));
|
||||
}
|
||||
return redirect()->back()
|
||||
->with('error', __('crud.messages.cannot_be_created', [
|
||||
'model' => Str::singular(__('models.classes.news'))
|
||||
]));
|
||||
|
||||
return redirect()
|
||||
->back()
|
||||
->with('error', trans(
|
||||
':model n\'a pas été créé',
|
||||
['model' => Str::singular(trans('models.classes.news'))]
|
||||
));
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -116,68 +111,73 @@ class NewsController extends Controller
|
|||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\Models\News $news
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit(News $news): \Illuminate\Contracts\View\View
|
||||
public function edit(News $news)
|
||||
{
|
||||
$newsCategories = NewsCategory::all();
|
||||
$newsProducts = Product::all();
|
||||
$newsList = News::where('id', '!=', $news->id)->get();
|
||||
|
||||
$newsList = collect($newsList)->each(function (News $value) {
|
||||
$value->setAttribute('label', $value->title);
|
||||
$newsList = collect($newsList)->each(function (\App\Models\News &$value) {
|
||||
$value->label = $value->title;
|
||||
});
|
||||
|
||||
$newsSelected = collect([]);
|
||||
collect($news->news ?? [])->each(function (News $value) use (&$newsSelected) {
|
||||
$value->setAttribute('label', $value->title);
|
||||
collect($news->news ?? [])->each(function (\App\Models\News &$value) use (&$newsSelected) {
|
||||
$value->label = $value->title;
|
||||
$newsSelected = $newsSelected->concat([$value]);
|
||||
});
|
||||
|
||||
return view('bo.pages.news.edit', [
|
||||
'newsModel' => $news,
|
||||
'news' => $news,
|
||||
'newsCategories' => $newsCategories,
|
||||
'newsProducts' => $newsProducts,
|
||||
'newsList' => $newsList,
|
||||
'newsProducts' => $newsProducts,
|
||||
'newsList' => $newsList,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \App\Http\Requests\Bo\News\UpdateNewsRequest $request
|
||||
* @param \App\Models\News $news
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @param \App\Http\Requests\Bo\News\UpdateNewsRequest $request
|
||||
* @param \App\Models\News $news
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(UpdateNewsRequest $request, News $news): \Illuminate\Http\RedirectResponse
|
||||
public function update(UpdateNewsRequest $request, News $news)
|
||||
{
|
||||
return DB::transaction(function () use ($request, $news) {
|
||||
$news->categories()->sync($request->categories_list);
|
||||
$news->products()->sync($request->products_list);
|
||||
$news->news()->sync($request->news_list);
|
||||
|
||||
$news->fill($request->safe()->except(['categories', 'products', 'associated_news_list']));
|
||||
$news->fill($request->validated());
|
||||
|
||||
if ($news->saveOrFail()) {
|
||||
return redirect()->route('bo.news.edit', $news->id)
|
||||
->with('success', __('crud.messages.has_been_updated', [
|
||||
'model' => Str::singular(__('models.classes.news'))
|
||||
]));
|
||||
return redirect()
|
||||
->route('bo.news.edit', $news)
|
||||
->with('success', trans(
|
||||
':model a été mis à jour',
|
||||
['model' => Str::singular(trans('models.classes.news'))]
|
||||
));
|
||||
}
|
||||
return redirect()->route('bo.news.edit', $news->id)
|
||||
->with('error', __('crud.messages.cannot_be_updated', [
|
||||
'model' => Str::singular(__('models.classes.news'))
|
||||
]));
|
||||
|
||||
return redirect()
|
||||
->back()
|
||||
->with('error', trans(
|
||||
':model n\'a pas été mis à jour',
|
||||
['model' => Str::singular(trans('models.classes.news'))]
|
||||
));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\News $news
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @param \App\Models\News $news
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy(News $news): \Illuminate\Http\RedirectResponse
|
||||
public function destroy(News $news)
|
||||
{
|
||||
DB::table('news_news')->where($news->news()->getRelatedPivotKeyName(), $news->id)->delete();
|
||||
$news->categories()->sync([]);
|
||||
|
|
@ -185,14 +185,19 @@ class NewsController extends Controller
|
|||
$news->news()->sync([]);
|
||||
|
||||
if ($news->deleteOrFail()) {
|
||||
return redirect()->route('bo.news.index')
|
||||
->with('success', __('crud.messages.has_been_deleted', [
|
||||
'model' => Str::singular(__('models.classes.news'))
|
||||
]));
|
||||
return redirect()
|
||||
->route('bo.news.index')
|
||||
->with('warning', trans(
|
||||
':model a bien été supprimé',
|
||||
['model' => Str::singular(trans('models.classes.news'))]
|
||||
));
|
||||
}
|
||||
return redirect()->back()
|
||||
->with('error', __('crud.messages.cannot_be_deleted', [
|
||||
'model' => Str::singular(__('models.classes.news'))
|
||||
]));
|
||||
|
||||
return redirect()
|
||||
->back()
|
||||
->with('error', trans(
|
||||
':model n\'a pas été supprimé',
|
||||
['model' => Str::singular(trans('models.classes.news'))]
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,110 +2,92 @@
|
|||
|
||||
namespace App\Http\Controllers\Bo;
|
||||
|
||||
use App\Enums\TagTypeEnum;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Bo\Products\StoreProductRequest;
|
||||
use App\Http\Requests\Bo\Products\UpdateProductRequest;
|
||||
use App\Lib\Helpers\FileStorageHelper;
|
||||
use App\Models\Product;
|
||||
use App\Models\Range;
|
||||
use App\Models\Subrange;
|
||||
use App\Models\Tag;
|
||||
use App\Traits\Controllers\UpdateModelPublished;
|
||||
use App\Traits\Controllers\ManagesOrder;
|
||||
use App\Traits\Controllers\HasPicture;
|
||||
use App\Traits\Controllers\UpdateModelStatus;
|
||||
use App\Traits\Models\ChangesModelOrder;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class ProductController extends Controller
|
||||
{
|
||||
use UpdateModelPublished;
|
||||
use ManagesOrder;
|
||||
use ChangesModelOrder;
|
||||
use UpdateModelStatus;
|
||||
use HasPicture;
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index(Request $request): \Illuminate\Contracts\View\View
|
||||
public function index(Request $request)
|
||||
{
|
||||
/** @var \Illuminate\Database\Eloquent\Builder $productModels */
|
||||
$productModels = Product::query();
|
||||
/** @var \Illuminate\Database\Eloquent\Builder $products */
|
||||
$products = Product::query();
|
||||
|
||||
/** @var string $search Search field */
|
||||
$search = $request->search;
|
||||
if ($search) {
|
||||
if ($request->search) {
|
||||
$this->searchQuery(
|
||||
$productModels,
|
||||
$search,
|
||||
$products,
|
||||
$request->search,
|
||||
null,
|
||||
'label'
|
||||
);
|
||||
}
|
||||
|
||||
if ($request->range) {
|
||||
$productModels->whereHas('subrange', function ($q) use ($request) {
|
||||
$q->where('subranges.range_id', '=', $request->range);
|
||||
})->get();
|
||||
}
|
||||
|
||||
$this->sortQuery($products);
|
||||
$searchFields = trans('Label');
|
||||
|
||||
/** Sort columns with a query */
|
||||
$this->sortQuery($productModels);
|
||||
$products = $products->paginate(10);
|
||||
|
||||
/** Custom pagination */
|
||||
$productModels = $this->paginate($productModels);
|
||||
|
||||
$ranges = Range::all();
|
||||
|
||||
return view('bo.pages.products.index', compact('productModels', 'search', 'searchFields', 'ranges'));
|
||||
return view('bo.pages.products.index', compact('products', 'searchFields'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @param \App\Models\Product $product
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create(Product $product): \Illuminate\Contracts\View\View
|
||||
public function create()
|
||||
{
|
||||
/** @var \Illuminate\Database\Eloquent\Builder $subrangeModels */
|
||||
$subrangeModels = Subrange::get();
|
||||
$productTags = Tag::query()->where('type', TagTypeEnum::products)->select(['id', 'label', 'slug'])->get();
|
||||
/** @var \Illuminate\Database\Eloquent\Builder $subranges */
|
||||
$subranges = Subrange::get();
|
||||
|
||||
return view('bo.pages.products.create', [
|
||||
'productModel' => $product,
|
||||
'subrangeModels' => $subrangeModels,
|
||||
'productTags' => $productTags,
|
||||
]);
|
||||
return view('bo.pages.products.create', compact('subranges'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \App\Http\Requests\Bo\Products\StoreProductRequest $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @param \App\Http\Requests\Bo\Products\StoreProductRequest $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(StoreProductRequest $request): \Illuminate\Http\RedirectResponse
|
||||
public function store(StoreProductRequest $request)
|
||||
{
|
||||
return DB::transaction(function () use ($request) {
|
||||
$product = new Product();
|
||||
$product->fill($request->safe()->except('tags'));
|
||||
$product->fill($request->validated());
|
||||
$this->storePictures($request, $product);
|
||||
|
||||
if ($product->saveOrFail()) {
|
||||
$product->tags()->sync(collect($request->input('tags'))->pluck('id'));
|
||||
return redirect()->route('bo.products.edit', $product->id)
|
||||
->with('success', __('crud.messages.has_been_created', [
|
||||
'model' => Str::singular(__('models.classes.products'))
|
||||
]));
|
||||
return redirect()
|
||||
->route('bo.products.edit', $product)
|
||||
->with('success', trans(
|
||||
':model a été créé',
|
||||
['model' => Str::singular(trans('models.classes.products'))]
|
||||
));
|
||||
}
|
||||
return redirect()->back()
|
||||
->with('error', __('crud.messages.cannot_be_created', [
|
||||
'model' => Str::singular(__('models.classes.products'))
|
||||
]));
|
||||
return redirect()
|
||||
->back()
|
||||
->with('error', trans(
|
||||
':model n\'a pas été créé',
|
||||
['model' => Str::singular(trans('models.classes.products'))]
|
||||
));
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -113,21 +95,14 @@ class ProductController extends Controller
|
|||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\Models\Product $product
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit(Product $product): \Illuminate\Contracts\View\View
|
||||
public function edit(Product $product)
|
||||
{
|
||||
/** @var \Illuminate\Database\Eloquent\Builder $subrangeModels */
|
||||
$subrangeModels = Subrange::get();
|
||||
/** @var \Illuminate\Database\Eloquent\Builder $subranges */
|
||||
$subranges = Subrange::get();
|
||||
|
||||
$productTags = Tag::query()->where('type', TagTypeEnum::products)
|
||||
->select(['id', 'label', 'slug'])->get();
|
||||
|
||||
return view('bo.pages.products.edit', [
|
||||
'productModel' => $product,
|
||||
'subrangeModels' => $subrangeModels,
|
||||
'productTags' => $productTags,
|
||||
]);
|
||||
return view('bo.pages.products.edit', ['product' => $product], compact('subranges'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -135,67 +110,55 @@ class ProductController extends Controller
|
|||
*
|
||||
* @param \App\Http\Requests\Bo\Products\UpdateProductRequest $request
|
||||
* @param \App\Models\Product $product
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(UpdateProductRequest $request, Product $product): \Illuminate\Http\RedirectResponse
|
||||
public function update(UpdateProductRequest $request, Product $product)
|
||||
{
|
||||
return DB::transaction(function () use ($request, $product) {
|
||||
$product->tags()->sync(collect($request->input('tags'))->pluck('id'));
|
||||
$product->fill($request->safe()->except('tags'));
|
||||
$product->fill($request->validated());
|
||||
$this->storePictures($request, $product);
|
||||
|
||||
if ($product->saveOrFail()) {
|
||||
return redirect()->route('bo.products.edit', $product->id)
|
||||
->with('success', __('crud.messages.has_been_updated', [
|
||||
'model' => Str::singular(__('models.classes.products'))
|
||||
]));
|
||||
return redirect()
|
||||
->route('bo.products.edit', $product)
|
||||
->with('success', trans(
|
||||
':model a été mis à jour',
|
||||
['model' => Str::singular(trans('models.classes.products'))]
|
||||
));
|
||||
}
|
||||
return redirect()->route('bo.products.edit', $product->id)
|
||||
->with('error', __('crud.messages.cannot_be_updated', [
|
||||
'model' => Str::singular(__('models.classes.products'))
|
||||
]));
|
||||
return redirect()
|
||||
->back()
|
||||
->with('error', trans(
|
||||
':model n\'a pas été mis à jour',
|
||||
['model' => Str::singular(trans('models.classes.products'))]
|
||||
));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\Product $product
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @param \App\Models\Product $product
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy(Product $product): \Illuminate\Http\RedirectResponse
|
||||
public function destroy(Product $product)
|
||||
{
|
||||
$product->advices()->sync([]);
|
||||
$product->news()->sync([]);
|
||||
$product->tags()->sync([]);
|
||||
|
||||
if ($product->deleteOrFail()) {
|
||||
return redirect()->route('bo.products.index')
|
||||
->with('success', __('crud.messages.has_been_deleted', [
|
||||
'model' => Str::singular(__('models.classes.products'))
|
||||
]));
|
||||
}
|
||||
return redirect()->back()
|
||||
->with('error', __('crud.messages.cannot_be_deleted', [
|
||||
'model' => Str::singular(__('models.classes.products'))
|
||||
]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Save Model Images
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \App\Models\Product $product
|
||||
* @return void
|
||||
*/
|
||||
private function storePictures(Request $request, Product $product)
|
||||
{
|
||||
if (is_array($request->input('slider_pictures'))) {
|
||||
$product->slider_pictures = [];
|
||||
$product->slider_pictures = collect($request->file('slider_pictures'))
|
||||
->map(function ($picture) use ($product) {
|
||||
return FileStorageHelper::storeFile($product, $picture, true);
|
||||
})->all();
|
||||
return redirect()
|
||||
->route('bo.products.index')
|
||||
->with('warning', trans(
|
||||
':model a bien été supprimé',
|
||||
['model' => Str::singular(trans('models.classes.products'))]
|
||||
));
|
||||
}
|
||||
return redirect()
|
||||
->back()
|
||||
->with('error', trans(
|
||||
':model n\'a pas été supprimé',
|
||||
['model' => Str::singular(trans('models.classes.products'))]
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ namespace App\Http\Controllers\Bo;
|
|||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Bo\Ranges\UpdateRangeRequest;
|
||||
use App\Models\Range;
|
||||
use App\Traits\Controllers\ChangesModelOrder;
|
||||
use App\Traits\Models\ChangesModelOrder;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
|
@ -18,43 +18,41 @@ class RangeController extends Controller
|
|||
* Display a listing of the resource.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index(Request $request): \Illuminate\Contracts\View\View
|
||||
public function index(Request $request)
|
||||
{
|
||||
/** @var \Illuminate\Database\Eloquent\Builder $rangeModels */
|
||||
$rangeModels = Range::query();
|
||||
/** @var \Illuminate\Database\Eloquent\Builder $ranges */
|
||||
$ranges = Range::query();
|
||||
|
||||
/** @var string $search Search field */
|
||||
$search = $request->search;
|
||||
if ($search) {
|
||||
if ($request->search) {
|
||||
$this->searchQuery(
|
||||
$rangeModels,
|
||||
$search,
|
||||
$ranges,
|
||||
$request->search,
|
||||
null,
|
||||
'label'
|
||||
);
|
||||
}
|
||||
|
||||
$this->sortQuery($ranges);
|
||||
$searchFields = trans('Libellé');
|
||||
|
||||
/** Sort columns with a query */
|
||||
$this->sortQuery($rangeModels);
|
||||
$ranges = $ranges->paginate(10);
|
||||
|
||||
/** Custom pagination */
|
||||
$rangeModels = $this->paginate($rangeModels);
|
||||
|
||||
return view('bo.pages.ranges.index', compact('rangeModels', 'search', 'searchFields'));
|
||||
return view('bo.pages.ranges.index', compact('ranges', 'searchFields'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\Models\Range $range
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit(Range $range): \Illuminate\Contracts\View\View
|
||||
public function edit(Range $range)
|
||||
{
|
||||
return view('bo.pages.ranges.edit', ['rangeModel' => $range]);
|
||||
return view('bo.pages.ranges.edit', [
|
||||
'range' => $range
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -62,23 +60,22 @@ class RangeController extends Controller
|
|||
*
|
||||
* @param \App\Http\Requests\Bo\Ranges\UpdateRangeRequest $request
|
||||
* @param \App\Models\Range $range
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(UpdateRangeRequest $request, Range $range): \Illuminate\Http\RedirectResponse
|
||||
public function update(UpdateRangeRequest $request, Range $range)
|
||||
{
|
||||
return DB::transaction(function () use ($request, $range) {
|
||||
$range->fill($request->validated());
|
||||
|
||||
if ($range->saveOrFail()) {
|
||||
return redirect()->route('bo.ranges.edit', $range->id)
|
||||
->with('success', __('crud.messages.has_been_updated', [
|
||||
'model' => Str::singular(__('models.classes.ranges'))
|
||||
]));
|
||||
return redirect()
|
||||
->route('bo.ranges.edit', $range)
|
||||
->with('success', trans(
|
||||
':model a été mis à jour',
|
||||
['model' => Str::singular(trans('models.classes.ranges'))]
|
||||
));
|
||||
}
|
||||
return redirect()->route('bo.ranges.edit', $range->id)
|
||||
->with('error', __('crud.messages.cannot_be_updated', [
|
||||
'model' => Str::singular(__('models.classes.ranges'))
|
||||
]));
|
||||
return redirect()->back();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,8 +6,7 @@ use App\Http\Controllers\Controller;
|
|||
use App\Http\Requests\Bo\Slides\StoreSlideRequest;
|
||||
use App\Http\Requests\Bo\Slides\UpdateSlideRequest;
|
||||
use App\Models\Slide;
|
||||
use App\Traits\Controllers\ChangesModelOrder;
|
||||
use App\Traits\Controllers\UpdateModelPublished;
|
||||
use App\Traits\Models\ChangesModelOrder;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
|
@ -15,74 +14,67 @@ use Illuminate\Support\Str;
|
|||
class SlideController extends Controller
|
||||
{
|
||||
use ChangesModelOrder;
|
||||
use UpdateModelPublished;
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index(Request $request): \Illuminate\Contracts\View\View
|
||||
public function index(Request $request)
|
||||
{
|
||||
/** @var \Illuminate\Database\Eloquent\Builder $slideModels */
|
||||
$slideModels = Slide::query();
|
||||
/** @var \Illuminate\Database\Eloquent\Builder $slides */
|
||||
$slides = Slide::query();
|
||||
|
||||
/** @var string $search Search field */
|
||||
$search = $request->search;
|
||||
if ($search) {
|
||||
if ($request->search) {
|
||||
$this->searchQuery(
|
||||
$slideModels,
|
||||
$search,
|
||||
$slides,
|
||||
$request->search,
|
||||
null,
|
||||
'title',
|
||||
'content',
|
||||
);
|
||||
}
|
||||
|
||||
$this->sortQuery($slides);
|
||||
$searchFields = trans('Titre, Contenu');
|
||||
|
||||
/** Sort columns with a query */
|
||||
$this->sortQuery($slideModels);
|
||||
$slides = $slides->paginate(10);
|
||||
|
||||
/** Custom pagination */
|
||||
$slideModels = $this->paginate($slideModels);
|
||||
|
||||
return view('bo.pages.slides.index', compact('slideModels', 'search', 'searchFields'));
|
||||
return view('bo.pages.slides.index', compact('slides', 'searchFields'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @param \App\Models\Slide $slide
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create(Slide $slide): \Illuminate\Contracts\View\View
|
||||
public function create()
|
||||
{
|
||||
return view('bo.pages.slides.create', ['slideModel' => $slide]);
|
||||
return view('bo.pages.slides.create');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \App\Http\Requests\Bo\Slides\StoreSlideRequest $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(StoreSlideRequest $request): \Illuminate\Http\RedirectResponse
|
||||
public function store(StoreSlideRequest $request)
|
||||
{
|
||||
return DB::transaction(function () use ($request) {
|
||||
$slide = new Slide();
|
||||
$slide->fill($request->validated());
|
||||
|
||||
if ($slide->saveOrFail()) {
|
||||
return redirect()->route('bo.slides.edit', $slide->id)
|
||||
->with('success', __('crud.messages.has_been_created', [
|
||||
'model' => Str::singular(__('models.classes.slides'))
|
||||
]));
|
||||
return redirect()
|
||||
->route('bo.slides.edit', $slide)
|
||||
->with('success', trans(
|
||||
':model a été créé',
|
||||
['model' => Str::singular(trans('models.classes.slides'))]
|
||||
));
|
||||
}
|
||||
return redirect()->back()
|
||||
->with('error', __('crud.messages.cannot_be_created', [
|
||||
'model' => Str::singular(__('models.classes.slides'))
|
||||
]));
|
||||
return back();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -90,11 +82,13 @@ class SlideController extends Controller
|
|||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\Models\Slide $slide
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit(Slide $slide): \Illuminate\Contracts\View\View
|
||||
public function edit(Slide $slide)
|
||||
{
|
||||
return view('bo.pages.slides.edit', ['slideModel' => $slide]);
|
||||
return view('bo.pages.slides.edit', [
|
||||
'slide' => $slide
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -102,23 +96,22 @@ class SlideController extends Controller
|
|||
*
|
||||
* @param \App\Http\Requests\Bo\Slides\UpdateSlideRequest $request
|
||||
* @param \App\Models\Slide $slide
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(UpdateSlideRequest $request, Slide $slide): \Illuminate\Http\RedirectResponse
|
||||
public function update(UpdateSlideRequest $request, Slide $slide)
|
||||
{
|
||||
return DB::transaction(function () use ($request, $slide) {
|
||||
$slide->fill($request->validated());
|
||||
|
||||
if ($slide->saveOrFail()) {
|
||||
return redirect()->route('bo.slides.edit', $slide->id)
|
||||
->with('success', __('crud.messages.has_been_updated', [
|
||||
'model' => Str::singular(__('models.classes.slides'))
|
||||
]));
|
||||
return redirect()
|
||||
->route('bo.slides.edit', $slide)
|
||||
->with('success', trans(
|
||||
':model a été mis à jour',
|
||||
['model' => Str::singular(trans('models.classes.slides'))]
|
||||
));
|
||||
}
|
||||
return redirect()->route('bo.slides.edit', $slide->id)
|
||||
->with('error', __('crud.messages.cannot_be_updated', [
|
||||
'model' => Str::singular(__('models.classes.slides'))
|
||||
]));
|
||||
return redirect()->back();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -126,19 +119,18 @@ class SlideController extends Controller
|
|||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\Slide $slide
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy(Slide $slide): \Illuminate\Http\RedirectResponse
|
||||
public function destroy(Slide $slide)
|
||||
{
|
||||
if ($slide->deleteOrFail()) {
|
||||
return redirect()->route('bo.slides.index')
|
||||
->with('success', __('crud.messages.has_been_deleted', [
|
||||
'model' => Str::singular(__('models.classes.slides'))
|
||||
]));
|
||||
return redirect()
|
||||
->route('bo.slides.index')
|
||||
->with('warning', trans(
|
||||
':model a bien été supprimé',
|
||||
['model' => Str::singular(trans('models.classes.slides'))]
|
||||
));
|
||||
}
|
||||
return redirect()->back()
|
||||
->with('error', __('crud.messages.cannot_be_deleted', [
|
||||
'model' => Str::singular(__('models.classes.slides'))
|
||||
]));
|
||||
return redirect()->back()->with('error', trans('Suppression impossible'));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,91 +0,0 @@
|
|||
<?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;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
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 */
|
||||
$staticPageModelList = $this->paginate($query);
|
||||
|
||||
return view('bo.pages.static_pages.index', compact('staticPageModelList', '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' => Str::ucfirst(\trans_choice('models.classes.static_page', 1))
|
||||
]));
|
||||
}
|
||||
return redirect()->route('bo.static_pages.edit', $static_page)
|
||||
->with('error', __('crud.messages.cannot_be_updated', [
|
||||
'model' => Str::ucfirst(\trans_choice('models.classes.static_page', 1))
|
||||
]));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace App\Http\Controllers\Bo;
|
||||
|
||||
use App\Enums\TagTypeEnum;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Bo\Tags\StoreTagRequest;
|
||||
use App\Http\Requests\Bo\Tags\UpdateTagRequest;
|
||||
|
|
@ -17,69 +16,67 @@ class TagController extends Controller
|
|||
* Display a listing of the resource.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index(Request $request): \Illuminate\Contracts\View\View
|
||||
public function index(Request $request)
|
||||
{
|
||||
/** @var \Illuminate\Database\Eloquent\Builder $tagModels */
|
||||
$tagModels = Tag::query();
|
||||
$tagModels = $request->type ? $tagModels->where('type', TagTypeEnum::{$request->type}) : $tagModels;
|
||||
/** @var \Illuminate\Database\Eloquent\Builder $tags */
|
||||
$tags = Tag::query();
|
||||
|
||||
/** @var string $search Search field */
|
||||
$search = $request->search;
|
||||
if ($search) {
|
||||
if ($request->search) {
|
||||
$this->searchQuery(
|
||||
$tagModels,
|
||||
$search,
|
||||
$tags,
|
||||
$request->search,
|
||||
null,
|
||||
'label',
|
||||
'type',
|
||||
'label'
|
||||
);
|
||||
}
|
||||
$searchFields = trans('Nom, Type');
|
||||
|
||||
/** Sort columns with a query */
|
||||
$this->sortQuery($tagModels);
|
||||
$this->sortQuery($tags);
|
||||
$searchFields = trans('Nom');
|
||||
|
||||
/** Custom pagination */
|
||||
$tagModels = $this->paginate($tagModels);
|
||||
$tags = $tags->paginate(10);
|
||||
|
||||
return view('bo.pages.tags.index', compact('tagModels', 'search', 'searchFields'));
|
||||
return view('bo.pages.tags.index', compact('tags', 'searchFields'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @param \App\Models\Tag $tag
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create(Tag $tag): \Illuminate\Contracts\View\View
|
||||
public function create()
|
||||
{
|
||||
return view('bo.pages.tags.create', ['tagModel' => $tag]);
|
||||
return view('bo.pages.tags.create');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \App\Http\Requests\Bo\Tags\StoreTagRequest $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @param \App\Http\Requests\Bo\Tags\StoreTagRequest $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(StoreTagRequest $request): \Illuminate\Http\RedirectResponse
|
||||
public function store(StoreTagRequest $request)
|
||||
{
|
||||
return DB::transaction(function () use ($request) {
|
||||
$tag = new Tag();
|
||||
$tag->fill($request->validated());
|
||||
|
||||
if ($tag->saveOrFail()) {
|
||||
return redirect()->route('bo.tags.edit', $tag->id)
|
||||
->with('success', __('crud.messages.has_been_created', [
|
||||
'model' => Str::singular(__('models.classes.tags'))
|
||||
]));
|
||||
return redirect()
|
||||
->route('bo.tags.edit', $tag)
|
||||
->with('success', trans(
|
||||
':model a été créé',
|
||||
['model' => Str::singular(trans('models.classes.tags'))]
|
||||
));
|
||||
}
|
||||
return redirect()->back()
|
||||
->with('error', __('crud.messages.cannot_be_created', [
|
||||
'model' => Str::singular(__('models.classes.tags'))
|
||||
]));
|
||||
|
||||
return redirect()
|
||||
->back()
|
||||
->with('error', trans(
|
||||
':model n\'a pas été créé',
|
||||
['model' => Str::singular(trans('models.classes.tags'))]
|
||||
));
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -87,9 +84,9 @@ class TagController extends Controller
|
|||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \App\Http\Requests\Bo\Tags\StoreTagRequest $request
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function jsonStore(StoreTagRequest $request): \Illuminate\Http\JsonResponse
|
||||
public function jsonStore(StoreTagRequest $request)
|
||||
{
|
||||
return DB::transaction(function () use ($request) {
|
||||
/** @var \App\Models\Tag */
|
||||
|
|
@ -104,57 +101,66 @@ class TagController extends Controller
|
|||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\Models\Tag $tag
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit(Tag $tag): \Illuminate\Contracts\View\View
|
||||
public function edit(Tag $tag)
|
||||
{
|
||||
return view('bo.pages.tags.edit', [
|
||||
'tagModel' => $tag,
|
||||
'tag' => $tag,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \App\Http\Requests\Bo\Tags\UpdateTagRequest $request
|
||||
* @param \App\Models\Tag $tag
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @param \App\Http\Requests\Bo\Tags\UpdateTagRequest $request
|
||||
* @param \App\Models\Tag $tag
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(UpdateTagRequest $request, Tag $tag): \Illuminate\Http\RedirectResponse
|
||||
public function update(UpdateTagRequest $request, Tag $tag)
|
||||
{
|
||||
return DB::transaction(function () use ($request, $tag) {
|
||||
$tag->fill($request->validated());
|
||||
|
||||
if ($tag->saveOrFail()) {
|
||||
return redirect()->route('bo.tags.edit', $tag->id)
|
||||
->with('success', __('crud.messages.has_been_updated', [
|
||||
'model' => Str::singular(__('models.classes.tags'))
|
||||
]));
|
||||
return redirect()
|
||||
->route('bo.tags.edit', $tag)
|
||||
->with('success', trans(
|
||||
':model a été mis à jour',
|
||||
['model' => Str::singular(trans('models.classes.tags'))]
|
||||
));
|
||||
}
|
||||
return redirect()->route('bo.tags.edit', $tag->id)
|
||||
->with('error', __('crud.messages.cannot_be_updated', [
|
||||
'model' => Str::singular(__('models.classes.tags'))
|
||||
]));
|
||||
return redirect()
|
||||
->back()
|
||||
->with('error', trans(
|
||||
':model n\'a pas été mis à jour',
|
||||
['model' => Str::singular(trans('models.classes.tags'))]
|
||||
));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\Tag $tag
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @param \App\Models\Tag $tag
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy(Tag $tag): \Illuminate\Http\RedirectResponse
|
||||
public function destroy(Tag $tag)
|
||||
{
|
||||
if ($tag->deleteOrFail()) {
|
||||
return redirect()->route('bo.tags.index')
|
||||
->with('success', __('crud.messages.has_been_deleted', [
|
||||
'model' => Str::singular(__('models.classes.tags'))
|
||||
]));
|
||||
return redirect()
|
||||
->route('bo.tags.index')
|
||||
->with('warning', trans(
|
||||
':model a bien été supprimé',
|
||||
['model' => Str::singular(trans('models.classes.tags'))]
|
||||
));
|
||||
}
|
||||
return redirect()->back()
|
||||
->with('error', __('crud.messages.cannot_be_deleted', [
|
||||
'model' => Str::singular(__('models.classes.tags'))
|
||||
]));
|
||||
|
||||
return redirect()
|
||||
->back()
|
||||
->with('error', trans(
|
||||
':model n\'a pas été supprimée',
|
||||
['model' => Str::singular(trans('models.classes.tags'))]
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,17 +3,15 @@
|
|||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Enums\Advices\AdviceTypeEnum;
|
||||
use App\Enums\Pagination\ItemsPerPaginationEnum;
|
||||
use App\Enums\Products\ProductSpeciesEnum;
|
||||
use App\Lib\Helpers\ToolboxHelper;
|
||||
use App\Models\Advice;
|
||||
use App\Models\News;
|
||||
use App\Models\Product;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||
use Illuminate\Routing\Controller as BaseController;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use Illuminate\Support\Str;
|
||||
|
|
@ -21,26 +19,28 @@ use Illuminate\Support\Str;
|
|||
class Controller extends BaseController
|
||||
{
|
||||
use AuthorizesRequests;
|
||||
use DispatchesJobs;
|
||||
use ValidatesRequests;
|
||||
|
||||
// Back search methods.
|
||||
|
||||
/**
|
||||
* Build Search query on specified fields
|
||||
* splitting search into words or using whole sentence
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query The eloquent query builder.
|
||||
* @param string $search The query string.
|
||||
* @param callable|null $searchQuery The query string.
|
||||
* @param string ...$fields Either a simple array or a string
|
||||
* in case of a string the two fields
|
||||
* would be concatenate to make the search.
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
* @param Builder $query The eloquent query builder.
|
||||
* @param string $search The query string.
|
||||
* @param callable $searchQuery The query string.
|
||||
* @param string ...$fields Either a simple array or a string
|
||||
* in case of a string the two fields would be concatenate to make the search.
|
||||
* @return Builder
|
||||
*/
|
||||
protected function searchQuery(
|
||||
Builder $query,
|
||||
string $search,
|
||||
callable|null $searchQuery = null,
|
||||
callable $searchQuery = null,
|
||||
string ...$fields
|
||||
): \Illuminate\Database\Eloquent\Builder {
|
||||
): Builder {
|
||||
if (count($fields)) {
|
||||
// Search using words.
|
||||
$words = explode(' ', $search);
|
||||
|
|
@ -64,162 +64,69 @@ class Controller extends BaseController
|
|||
/**
|
||||
* Build query search on all fields
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param string $search
|
||||
* @param array $fields
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
* @param Builder $query
|
||||
* @param string $search
|
||||
* @param array $fields
|
||||
* @return Builder
|
||||
*/
|
||||
private function searchOnFields(
|
||||
Builder $query,
|
||||
string $search,
|
||||
array $fields
|
||||
): \Illuminate\Database\Eloquent\Builder {
|
||||
private function searchOnFields(Builder $query, string $search, array $fields): Builder
|
||||
{
|
||||
$table = $query->getModel()->getTable();
|
||||
foreach ($fields as $field) {
|
||||
$field = str_replace('?', '\?', $field);
|
||||
if (is_array($field)) {
|
||||
foreach ($fields as $f) {
|
||||
$f = str_replace('?', '\?', $f);
|
||||
if (is_array($f)) {
|
||||
$query->orWhereRaw(
|
||||
sprintf("UPPER(CONCAT(%s)) LIKE UPPER(?)", collect($field)->map(function ($q) use ($table) {
|
||||
sprintf("UPPER(CONCAT(%s)) LIKE UPPER(?)", collect($f)->map(function ($q) use ($table) {
|
||||
return "`$table`.`$q`";
|
||||
})->implode(', \' \', ')),
|
||||
['%' . htmlspecialchars($search) . '%']
|
||||
['%' . filter_var($search, FILTER_SANITIZE_STRING) . '%']
|
||||
);
|
||||
} else {
|
||||
$query->orWhereRaw(
|
||||
"UPPER(`$table`.`$f`) LIKE UPPER(?)",
|
||||
['%' . filter_var($search, FILTER_SANITIZE_STRING) . '%']
|
||||
);
|
||||
return $query;
|
||||
}
|
||||
// Get models woth enum's label.
|
||||
if (is_array($this->getSearchValue($query, $search, $field))) {
|
||||
foreach ($this->getSearchValue($query, $search, $field) as $array) {
|
||||
$query->orWhereRaw(
|
||||
"UPPER(`$table`.`$field`) LIKE UPPER(?)",
|
||||
['%' . htmlspecialchars($array->value) . '%']
|
||||
);
|
||||
}
|
||||
return $query;
|
||||
}
|
||||
// Get models with relation's name/label.
|
||||
if (Str::endsWith($field, '_id')) {
|
||||
$query->orWhereHas(Str::remove('_id', $field), function ($queryRelation) use ($field, $search) {
|
||||
if (Schema::hasColumn(Str::remove('_id', $field) . 's', 'name')) {
|
||||
$queryRelation->where('name', 'like', '%' . $search . '%');
|
||||
} elseif (Schema::hasColumn(Str::remove('_id', $field) . 's', 'label')) {
|
||||
$queryRelation->where('label', 'like', '%' . $search . '%');
|
||||
}
|
||||
});
|
||||
return $query;
|
||||
}
|
||||
$query->orWhereRaw(
|
||||
"UPPER(`$table`.`$field`) LIKE UPPER(?)",
|
||||
['%' . htmlspecialchars($this->getSearchValue($query, $search, $field)) . '%']
|
||||
);
|
||||
} //end foreach
|
||||
}
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the search value (on string or Enum).
|
||||
* Sort columns with a query
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param string $search
|
||||
* @param string $field
|
||||
* @return string|array
|
||||
* @param Builder $query
|
||||
* @param array $ignore
|
||||
* @return Builder
|
||||
*/
|
||||
protected function getSearchValue(Builder $query, string $search, string $field): string|array
|
||||
{
|
||||
$cast = $query->getModel()->getCasts()[$field] ?? null;
|
||||
if (
|
||||
count($query->getModel()->getCasts()) and // Check if the model has casts.
|
||||
$cast and // Check if there is cast about specific field.
|
||||
enum_exists($cast) // Check if the cast is an enum.
|
||||
) {
|
||||
/** @var \App\Traits\Enums $cast */
|
||||
// @phpstan-ignore-next-line
|
||||
$cases = collect($cast::toArray());
|
||||
$enum = $cases->filter(function ($item) use ($search) {
|
||||
return preg_match('/' . Str::lower($search) . '/', Str::lower($item->label));
|
||||
});
|
||||
return $enum->toArray();
|
||||
} else {
|
||||
return $search;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort columns with a query.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param array $ignore
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
protected function sortQuery(Builder $query, array $ignore = []): \Illuminate\Database\Eloquent\Builder
|
||||
protected function sortQuery(Builder $query, array $ignore = []): Builder
|
||||
{
|
||||
$rName = request()->route()->getName();
|
||||
$table = $query->getModel()->getTable();
|
||||
if (request()->input('sort_col')) {
|
||||
Session::put("$rName.sort_col", request()->input('sort_col'));
|
||||
Session::put("$rName.sorted", true);
|
||||
if (request()->sort_col) {
|
||||
Session::put("$rName.sort_col", request()->sort_col);
|
||||
}
|
||||
if (request()->input('sort_way')) {
|
||||
Session::put("$rName.sort_way", request()->input('sort_way'));
|
||||
Session::put("$rName.sorted", true);
|
||||
if (request()->sort_way) {
|
||||
Session::put("$rName.sort_way", request()->sort_way);
|
||||
}
|
||||
if (request()->rst) {
|
||||
Session::remove("$rName.sorted");
|
||||
Session::remove("$rName.sort_col");
|
||||
Session::remove("$rName.sort_way");
|
||||
}
|
||||
if (
|
||||
request()->input('sort_col') and
|
||||
request()->input('sort_way') and
|
||||
Schema::hasColumn($table, request()->input('sort_col'))
|
||||
) {
|
||||
if (!in_array(request()->input('sort_col'), $ignore)) {
|
||||
$query = $query->orderBy(
|
||||
\sprintf("$table.%s", request()->input('sort_col')),
|
||||
request()->input('sort_way')
|
||||
);
|
||||
if (request()->sort_col and request()->sort_way and Schema::hasColumn($table, request()->sort_col)) {
|
||||
if (
|
||||
!isset($ignore) or
|
||||
(isset($ignore) and !in_array(request()->sort_col, $ignore))
|
||||
) {
|
||||
$query = $query->orderBy(\sprintf("$table.%s", request()->sort_col), request()->sort_way);
|
||||
}
|
||||
} elseif (Schema::hasColumn($table, 'order')) {
|
||||
$query = $query->orderBy('order', 'ASC');
|
||||
Session::put("$rName.sort_col", 'order');
|
||||
Session::put("$rName.sort_way", 'asc');
|
||||
} elseif (Schema::hasColumn($table, 'updated_at')) {
|
||||
$query = $query->orderBy('updated_at', 'DESC');
|
||||
Session::put("$rName.sort_col", 'updated_at');
|
||||
Session::put("$rName.sort_way", 'desc');
|
||||
} elseif (Schema::hasColumn($table, 'created_at')) {
|
||||
$query = $query->orderBy('created_at', 'DESC');
|
||||
Session::put("$rName.sort_col", 'created_at');
|
||||
Session::put("$rName.sort_way", 'desc');
|
||||
}
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Customize pagination with cache or config (default).
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param \App\Enums\Pagination\ItemsPerPaginationEnum|null $pagination
|
||||
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
|
||||
*/
|
||||
protected function paginate(
|
||||
Builder $query,
|
||||
ItemsPerPaginationEnum|null $pagination = null
|
||||
): \Illuminate\Contracts\Pagination\LengthAwarePaginator {
|
||||
$currentRoutePath = Str::slug(request()->route()->getName());
|
||||
$cacheKey = "pagination.{$currentRoutePath}";
|
||||
$pagination = $pagination ?? ItemsPerPaginationEnum::twelve;
|
||||
$pagination = ToolboxHelper::getValidatedEnum(
|
||||
Cache::get($cacheKey, $pagination->value()),
|
||||
'pagination',
|
||||
'\App\Enums\Pagination\ItemsPerPaginationEnum',
|
||||
);
|
||||
if (Cache::get($cacheKey) !== $pagination) {
|
||||
Cache::put($cacheKey, $pagination);
|
||||
}
|
||||
$query = $query->paginate($pagination);
|
||||
return $query;
|
||||
}
|
||||
|
||||
// Front Search methods.
|
||||
|
||||
/**
|
||||
|
|
@ -237,7 +144,7 @@ class Controller extends BaseController
|
|||
*/
|
||||
protected function getProductQuery(string $search): Builder
|
||||
{
|
||||
return Product::query()->where('published', true)->where(function ($query) use ($search) {
|
||||
return Product::query()->where('status', true)->where(function ($query) use ($search) {
|
||||
// Par leur désignation.
|
||||
$query->where('label', 'like', "%{$search}%");
|
||||
// Par ingrédients.
|
||||
|
|
@ -257,12 +164,12 @@ class Controller extends BaseController
|
|||
// Par espèce.
|
||||
if (\strlen($search)) {
|
||||
/** @var \App\Enums\Products\ProductSpeciesEnum|null $specie */
|
||||
$specie = \collect(ProductSpeciesEnum::cases())
|
||||
$specie = \collect(ProductSpeciesEnum::toArray())
|
||||
->filter(function (ProductSpeciesEnum $specie) use ($search) {
|
||||
return \strpos(Str::lower($specie->label()), Str::lower($search)) !== false;
|
||||
return \strpos(Str::lower($specie->label), Str::lower($search)) !== false;
|
||||
})->first();
|
||||
if ($specie) {
|
||||
$query->orWhere('species', $specie->value());
|
||||
$query->orWhere('species', $specie);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -279,7 +186,7 @@ class Controller extends BaseController
|
|||
*/
|
||||
protected function getNewsQuery(string $search): Builder
|
||||
{
|
||||
return News::query()->where('published', true)->where(function ($query) use ($search) {
|
||||
return News::query()->where('status', true)->where(function ($query) use ($search) {
|
||||
$query->where('title', 'like', "%{$search}%");
|
||||
$query->orWhere('subtitle', 'like', "%{$search}%");
|
||||
$query->orWhere('content', 'like', "%{$search}%");
|
||||
|
|
@ -298,8 +205,8 @@ class Controller extends BaseController
|
|||
*/
|
||||
protected function getRecipeQuery(string $search): Builder
|
||||
{
|
||||
return Advice::query()->where('published', true)
|
||||
->where('type', '=', AdviceTypeEnum::recipes->value)
|
||||
return Advice::query()->where('status', true)
|
||||
->where('type', '=', AdviceTypeEnum::recipes()->value)
|
||||
->where(function ($query) use ($search) {
|
||||
$query->where('title', 'like', "%{$search}%");
|
||||
$query->orWhere('preparation', 'like', "%{$search}%");
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ class ActivitiesController extends Controller
|
|||
*
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function sociale(): \Illuminate\Contracts\View\View
|
||||
public function sociale()
|
||||
{
|
||||
// phpcs:disable
|
||||
$activity_title = "Restauration sociale";
|
||||
|
|
@ -43,7 +43,7 @@ class ActivitiesController extends Controller
|
|||
*
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function commerciale(): \Illuminate\Contracts\View\View
|
||||
public function commerciale()
|
||||
{
|
||||
// phpcs:disable
|
||||
$activity_title = "Restauration commerciale";
|
||||
|
|
@ -55,7 +55,7 @@ class ActivitiesController extends Controller
|
|||
La pintade et le canard pour des repas gourmands. <br><br>
|
||||
Des produits cuits pour plus de praticité et des services rapides. <br><br>
|
||||
Une large gamme de pané pour la création de burger.<br><br>
|
||||
Ou encore de nombreux produits pour la réalisation des menu enfants.";
|
||||
Ou encore de nombreux produits pour la réalisation des menu enfants.";
|
||||
// phpcs:enable
|
||||
$activity_image = "restau-commerciale.jpg";
|
||||
|
||||
|
|
@ -77,7 +77,7 @@ class ActivitiesController extends Controller
|
|||
*
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function distributeur(): \Illuminate\Contracts\View\View
|
||||
public function distributeur()
|
||||
{
|
||||
// phpcs:disable
|
||||
$activity_title = "Distributeur";
|
||||
|
|
@ -108,7 +108,7 @@ class ActivitiesController extends Controller
|
|||
*
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function boulangerie(): \Illuminate\Contracts\View\View
|
||||
public function boulangerie()
|
||||
{
|
||||
// phpcs:disable
|
||||
$activity_title = "Boul Pat";
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ class AdnController extends Controller
|
|||
*
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function index(): \Illuminate\Contracts\View\View
|
||||
public function index()
|
||||
{
|
||||
return view('fo.pages.adn.adn');
|
||||
}
|
||||
|
|
@ -21,7 +21,17 @@ class AdnController extends Controller
|
|||
*
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function btob(): \Illuminate\Contracts\View\View
|
||||
public function story()
|
||||
{
|
||||
return view('fo.pages.adn.story');
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function btob()
|
||||
{
|
||||
return view('fo.pages.adn.btob');
|
||||
}
|
||||
|
|
@ -31,7 +41,7 @@ class AdnController extends Controller
|
|||
*
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function breeder(): \Illuminate\Contracts\View\View
|
||||
public function breeder()
|
||||
{
|
||||
return view('fo.pages.adn.breeder');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ class BreederController extends Controller
|
|||
*
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function index(): \Illuminate\Contracts\View\View
|
||||
public function index()
|
||||
{
|
||||
return view('fo.pages.breeder');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,26 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Fo;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\BrigadeSection;
|
||||
|
||||
class BrigadeController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function index(): \Illuminate\Contracts\View\View
|
||||
{
|
||||
$sections = BrigadeSection::query()
|
||||
->where('published', true)
|
||||
->orderBy('order')
|
||||
->get();
|
||||
|
||||
return view('fo.pages.brigade', compact(
|
||||
'sections',
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
@ -11,7 +11,7 @@ class BusinessController extends Controller
|
|||
*
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function index(): \Illuminate\Contracts\View\View
|
||||
public function index()
|
||||
{
|
||||
return view('fo.pages.btob');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,18 +2,13 @@
|
|||
|
||||
namespace App\Http\Controllers\Fo;
|
||||
|
||||
use App\Enums\StaticPageType;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Fo\Contact\ContactRequest;
|
||||
use App\Mail\ContactFormMail;
|
||||
use App\Models\StaticPage;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use App\Enums\Contact\ContactActivityEnum;
|
||||
use App\Enums\Contact\ContactTimeEnum;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use LDC\LDCCRM\Exceptions\ApiErrorException;
|
||||
use LDC\LDCCRM\Exceptions\CrmException;
|
||||
use LDC\LDCCRM\Models\SingleOptin;
|
||||
|
||||
class ContactController extends Controller
|
||||
{
|
||||
|
|
@ -22,11 +17,9 @@ class ContactController extends Controller
|
|||
*
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function index(): \Illuminate\Contracts\View\View
|
||||
public function index()
|
||||
{
|
||||
/** @var \App\Models\StaticPage */
|
||||
$staticPageModel = StaticPage::query()->where('type', StaticPageType::contact)->firstOrFail();
|
||||
return view('fo.pages.contact', compact('staticPageModel'));
|
||||
return view('fo.pages.contact');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -37,63 +30,17 @@ class ContactController extends Controller
|
|||
*/
|
||||
public function contactSubmit(ContactRequest $request): \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
$recipients = config('mail.contactsList.contactform');
|
||||
$request->merge([
|
||||
'activityEnum' => ContactActivityEnum::toArray()[$request->activity - 1],
|
||||
'callTimeEnum' => ContactTimeEnum::toArray()[$request->callTime - 1]
|
||||
]);
|
||||
|
||||
if (empty($recipients)) {
|
||||
Log::warning('Aucun destinataire configuré pour le formulaire de contact.');
|
||||
return back()
|
||||
->withErrors(['global' => __('Une erreur est survenue, veuillez réessayer plus tard.')])
|
||||
->withInput();
|
||||
}
|
||||
$redirection = back()->with('success', trans(
|
||||
'Votre message a bien été envoyé, merci de votre intérêt, nous répondrons dans les meilleurs délais.'
|
||||
));
|
||||
|
||||
if ($request->opt_in) {
|
||||
try {
|
||||
SingleOptin::setStatus($request->email, true);
|
||||
} catch (ApiErrorException $e) {
|
||||
\report($e);
|
||||
$redirection = $redirection->withErrors([
|
||||
'opt_in' => trans('Une erreur est survenue,
|
||||
votre inscription à la newsletter n\'a pas été prise en compte.')
|
||||
]);
|
||||
} catch (CrmException $e) {
|
||||
\report($e);
|
||||
$redirection = $redirection->withErrors([
|
||||
'opt_in' => trans('Une erreur est survenue,
|
||||
votre inscription à la newsletter n\'a pas été prise en compte.')
|
||||
]);
|
||||
}
|
||||
} //end if
|
||||
|
||||
foreach ($recipients as $recipient) {
|
||||
Mail::to($recipient)->send(new ContactFormMail($request));
|
||||
}
|
||||
Mail::to(config('mail.contactsList.contactform'))->send(new ContactFormMail($request));
|
||||
|
||||
Session::forget('saveProductInBasket');
|
||||
|
||||
Session::forget('contact_draft');
|
||||
|
||||
Session::flash('matomo_generate_lead');
|
||||
|
||||
return $redirection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save data form as draft
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function saveDraft(Request $request): \Illuminate\Http\JsonResponse
|
||||
{
|
||||
$request->session()->put('contact_draft', $request->only([
|
||||
'firstname', 'lastname', 'email', 'phone',
|
||||
'activity', 'society', 'postcode', 'city',
|
||||
'message', 'callTime', 'opt_in',
|
||||
]));
|
||||
|
||||
return response()->json(['success' => true]);
|
||||
return back()->with('success', trans(
|
||||
'Votre message a bien été envoyé, merci de votre intérêt, nous répondrons dans les meilleurs délais.'
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ class EngagmentsController extends Controller
|
|||
*
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function francais(): \Illuminate\Contracts\View\View
|
||||
public function francais()
|
||||
{
|
||||
return view('fo.pages.engagments.francais');
|
||||
}
|
||||
|
|
@ -21,7 +21,7 @@ class EngagmentsController extends Controller
|
|||
*
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function eleverdurablement(): \Illuminate\Contracts\View\View
|
||||
public function eleverdurablement()
|
||||
{
|
||||
return view('fo.pages.engagments.eleverdurablement');
|
||||
}
|
||||
|
|
@ -31,7 +31,7 @@ class EngagmentsController extends Controller
|
|||
*
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function biennourrir(): \Illuminate\Contracts\View\View
|
||||
public function biennourrir()
|
||||
{
|
||||
return view('fo.pages.engagments.biennourrir');
|
||||
}
|
||||
|
|
@ -41,7 +41,7 @@ class EngagmentsController extends Controller
|
|||
*
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function respecterlaterre(): \Illuminate\Contracts\View\View
|
||||
public function respecterlaterre()
|
||||
{
|
||||
return view('fo.pages.engagments.respecterlaterre');
|
||||
}
|
||||
|
|
@ -51,7 +51,7 @@ class EngagmentsController extends Controller
|
|||
*
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function vivreensemble(): \Illuminate\Contracts\View\View
|
||||
public function vivreensemble()
|
||||
{
|
||||
return view('fo.pages.engagments.vivreensemble');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,125 +5,121 @@ namespace App\Http\Controllers\Fo;
|
|||
use App\Enums\Advices\AdviceTypeEnum;
|
||||
use App\Enums\ExpertiseProducts\ExpertiseProductPageEnum;
|
||||
use App\Enums\Products\ProductSpeciesEnum;
|
||||
use App\Enums\StaticPageType;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Advice;
|
||||
use App\Models\ExpertiseProduct;
|
||||
use App\Models\Product;
|
||||
use App\Models\StaticPage;
|
||||
use Illuminate\Contracts\Database\Eloquent\Builder;
|
||||
|
||||
class ExpertiseController extends Controller
|
||||
{
|
||||
/**
|
||||
* Show expertise page (duck).
|
||||
* Undocumented function
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*
|
||||
*/
|
||||
public function canard(): \Illuminate\Contracts\View\View
|
||||
public function canard()
|
||||
{
|
||||
return view('fo.pages.expertise.canard', $this->getExpertiseData(
|
||||
StaticPageType::expertise_duck,
|
||||
ExpertiseProductPageEnum::duck,
|
||||
ProductSpeciesEnum::canard
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show expertise page (turkey).
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function dinde(): \Illuminate\Contracts\View\View
|
||||
{
|
||||
return view('fo.pages.expertise.dinde', $this->getExpertiseData(
|
||||
StaticPageType::expertise_turkey,
|
||||
ExpertiseProductPageEnum::turkey,
|
||||
ProductSpeciesEnum::dinde
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show expertise page (rabbit).
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function lapin(): \Illuminate\Contracts\View\View
|
||||
{
|
||||
return view('fo.pages.expertise.lapin', $this->getExpertiseData(
|
||||
StaticPageType::expertise_rabbit,
|
||||
ExpertiseProductPageEnum::rabbit,
|
||||
ProductSpeciesEnum::lapin
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show expertise page (guineafowl).
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function pintade(): \Illuminate\Contracts\View\View
|
||||
{
|
||||
return view('fo.pages.expertise.pintade', $this->getExpertiseData(
|
||||
StaticPageType::expertise_guineafowl,
|
||||
ExpertiseProductPageEnum::guineafowl,
|
||||
ProductSpeciesEnum::pintade
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show expertise page (chicken).
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function poulet(): \Illuminate\Contracts\View\View
|
||||
{
|
||||
return view('fo.pages.expertise.poulet', $this->getExpertiseData(
|
||||
StaticPageType::expertise_chicken,
|
||||
ExpertiseProductPageEnum::chicken,
|
||||
ProductSpeciesEnum::poulet
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all expertise data needed.
|
||||
*
|
||||
* @param \App\Enums\StaticPageType $enumStaticPageType
|
||||
* @param \App\Enums\ExpertiseProducts\ExpertiseProductPageEnum $enumExpertiseProductPage
|
||||
* @param \App\Enums\Products\ProductSpeciesEnum $enumProductSpecies
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getExpertiseData(
|
||||
StaticPageType $enumStaticPageType,
|
||||
ExpertiseProductPageEnum $enumExpertiseProductPage,
|
||||
ProductSpeciesEnum $enumProductSpecies
|
||||
): array {
|
||||
/** @var \App\Models\StaticPage $staticPageModel */
|
||||
$staticPageModel = StaticPage::query()->where('type', $enumStaticPageType->value())->first();
|
||||
|
||||
/** @var \App\Models\ExpertiseProduct $productVipModels */
|
||||
$productVipModels = ExpertiseProduct::query()->where('page', $enumExpertiseProductPage->value())->get();
|
||||
|
||||
/** @var \App\Models\Product $productModels */
|
||||
$productModels = Product::query()->where('published', true)
|
||||
->where('species', $enumProductSpecies->value())
|
||||
// Get VIP Products for this page.
|
||||
$vip = ExpertiseProduct::query()->where('page', ExpertiseProductPageEnum::duck()->value)->get();
|
||||
$products = Product::query()->where('status', true)
|
||||
->where('species', ProductSpeciesEnum::canard()->value)
|
||||
->inRandomOrder()
|
||||
->limit(3)
|
||||
->with('subrange.range')
|
||||
->get();
|
||||
$recipes = Advice::query()->whereHas('products', function ($query) {
|
||||
return $query->where('species', ProductSpeciesEnum::canard()->value);
|
||||
})->where('type', AdviceTypeEnum::recipes())->limit(3)->get();
|
||||
|
||||
$recipeModels = Advice::query()->with('tags')
|
||||
->whereHas('products', function (Builder $q) use ($enumProductSpecies) {
|
||||
return $q->where('species', $enumProductSpecies->value());
|
||||
})->where('type', AdviceTypeEnum::recipes)->limit(3)->get();
|
||||
return view('fo.pages.expertise.canard', compact('vip', 'products', 'recipes'));
|
||||
}
|
||||
|
||||
return [
|
||||
'staticPageModel' => $staticPageModel,
|
||||
'productVipModels' => $productVipModels,
|
||||
'productModels' => $productModels,
|
||||
'recipeModels' => $recipeModels
|
||||
];
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function dinde()
|
||||
{
|
||||
// Get VIP Products for this page.
|
||||
$vip = ExpertiseProduct::query()->where('page', ExpertiseProductPageEnum::turkey()->value)->get();
|
||||
$products = Product::query()->where('status', true)
|
||||
->where('species', ProductSpeciesEnum::dinde()->value)
|
||||
->inRandomOrder()
|
||||
->limit(3)
|
||||
->with('subrange.range')
|
||||
->get();
|
||||
$recipes = Advice::query()->whereHas('products', function ($query) {
|
||||
return $query->where('species', ProductSpeciesEnum::dinde()->value);
|
||||
})->where('type', AdviceTypeEnum::recipes())->limit(3)->get();
|
||||
|
||||
return view('fo.pages.expertise.dinde', compact('vip', 'products', 'recipes'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function lapin()
|
||||
{
|
||||
// Get VIP Products for this page.
|
||||
$vip = ExpertiseProduct::query()->where('page', ExpertiseProductPageEnum::rabbit()->value)->get();
|
||||
$products = Product::query()->where('status', true)
|
||||
->where('species', ProductSpeciesEnum::lapin()->value)
|
||||
->inRandomOrder()
|
||||
->limit(3)
|
||||
->with('subrange.range')
|
||||
->get();
|
||||
$recipes = Advice::query()->whereHas('products', function ($query) {
|
||||
return $query->where('species', ProductSpeciesEnum::lapin()->value);
|
||||
})->where('type', AdviceTypeEnum::recipes())->limit(3)->get();
|
||||
|
||||
return view('fo.pages.expertise.lapin', compact('vip', 'products', 'recipes'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function pintade()
|
||||
{
|
||||
// Get VIP Products for this page.
|
||||
$vip = ExpertiseProduct::query()->where('page', ExpertiseProductPageEnum::guineafowl()->value)->get();
|
||||
$products = Product::query()->where('status', true)
|
||||
->where('species', ProductSpeciesEnum::pintade()->value)
|
||||
->inRandomOrder()
|
||||
->limit(3)
|
||||
->with('subrange.range')
|
||||
->get();
|
||||
$recipes = Advice::query()->whereHas('products', function ($query) {
|
||||
return $query->where('species', ProductSpeciesEnum::pintade()->value);
|
||||
})->where('type', AdviceTypeEnum::recipes())->limit(3)->get();
|
||||
|
||||
return view('fo.pages.expertise.pintade', compact('vip', 'products', 'recipes'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function poulet()
|
||||
{
|
||||
// Get VIP Products for this page.
|
||||
$vip = ExpertiseProduct::query()->where('page', ExpertiseProductPageEnum::chicken()->value)->get();
|
||||
$products = Product::query()->where('status', true)
|
||||
->where('species', ProductSpeciesEnum::poulet()->value)
|
||||
->inRandomOrder()
|
||||
->limit(3)
|
||||
->with('subrange.range')
|
||||
->get();
|
||||
$recipes = Advice::query()->whereHas('products', function ($query) {
|
||||
return $query->where('species', ProductSpeciesEnum::poulet()->value);
|
||||
})->where('type', AdviceTypeEnum::recipes())->limit(3)->get();
|
||||
|
||||
return view('fo.pages.expertise.poulet', compact('vip', 'products', 'recipes'));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,17 +3,12 @@
|
|||
namespace App\Http\Controllers\Fo;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Fo\Newsletter\SingleOptinRequest;
|
||||
use App\Http\Requests\Fo\Newsletter\UnsubscribeNewsletterRequest;
|
||||
use App\Models\News;
|
||||
use App\Models\Product;
|
||||
use App\Models\Range;
|
||||
use App\Models\Slide;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use LDC\LDCCRM\Enums\ApiError;
|
||||
use LDC\LDCCRM\Exceptions\ApiErrorException;
|
||||
use LDC\LDCCRM\Exceptions\CrmException;
|
||||
use LDC\LDCCRM\Models\SingleOptin;
|
||||
use Carbon\Carbon;
|
||||
use Spatie\CalendarLinks\Link;
|
||||
|
||||
class HomeController extends Controller
|
||||
{
|
||||
|
|
@ -22,106 +17,46 @@ class HomeController extends Controller
|
|||
*
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function index(): \Illuminate\Contracts\View\View
|
||||
public function index()
|
||||
{
|
||||
|
||||
// Get Slides.
|
||||
|
||||
/** @var \Illuminate\Database\Eloquent\Builder $slides */
|
||||
$slides = Slide::query()
|
||||
->where('published', true)
|
||||
->orderBy('order', 'DESC')
|
||||
->get();
|
||||
$slides = Slide::query();
|
||||
$this->sortQuery($slides);
|
||||
$slides->orderBy('order', 'DESC');
|
||||
$slides = $slides->get();
|
||||
|
||||
// Gammes.
|
||||
$ranges = Range::all();
|
||||
|
||||
// VIP Products.
|
||||
$threeproducts = Product::where('published', true)
|
||||
->where('is_vip', true)
|
||||
$threeproducts = Product::where('status', true)
|
||||
->where('is_vip', true)
|
||||
->take(3)
|
||||
->orderBy('priority_order', 'DESC')
|
||||
->orderBy('order', 'DESC')
|
||||
->with('subrange.range')
|
||||
->get();
|
||||
->get();
|
||||
|
||||
// Get Agenda.
|
||||
// Events starting in the future.
|
||||
$events = News::query()->where('published', true)
|
||||
->where('event_start', '>', now())
|
||||
->orderBy('event_start', 'desc')
|
||||
->take(2)->get()->reverse();
|
||||
$events = News::where('status', true)
|
||||
->where('event_start', '>', Carbon::now())
|
||||
->orderBy('event_start', 'desc')
|
||||
->take(2)->get();
|
||||
|
||||
$events = $events->reverse();
|
||||
|
||||
foreach ($events as $event) {
|
||||
$event->cal_link = Link::create($event->title, $event->event_start, $event->event_end)
|
||||
->description($event->event_text)
|
||||
->ics();
|
||||
}
|
||||
|
||||
// Get last 3 News.
|
||||
$news = News::query()->latest()->where('published', true)
|
||||
->take(3)->with('categories')->get();
|
||||
$news = News::latest()->where('status', true)->take(3)->with('categories')->get();
|
||||
|
||||
return view('fo.pages.home', compact(
|
||||
'slides',
|
||||
'ranges',
|
||||
'threeproducts',
|
||||
'events',
|
||||
'news'
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Call the CRM to add a single optin
|
||||
*
|
||||
* @param \App\Http\Requests\Fo\Newsletter\SingleOptinRequest $request
|
||||
* @return string|array|null|\Illuminate\Contracts\Translation\Translator
|
||||
* @throws \LDC\LDCCRM\Exceptions\ValidationException ValidationException.
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException BindingResolutionException.
|
||||
*/
|
||||
public function addOptIn(SingleOptinRequest $request)
|
||||
{
|
||||
try {
|
||||
SingleOptin::setStatus($request->email, true);
|
||||
return \response(trans("Votre inscription à la newsletter a été prise en compte"), 200);
|
||||
} catch (ApiErrorException $e) {
|
||||
\report($e);
|
||||
return \response(trans('Une erreur est survenue, merci de réessayer ultérieurement'), 500);
|
||||
} catch (CrmException $e) {
|
||||
\report($e);
|
||||
return \response(trans('Une erreur est survenue, merci de réessayer ultérieurement'), 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* unsubscribeNewsletter method
|
||||
*
|
||||
* @param \App\Http\Requests\Fo\Newsletter\UnsubscribeNewsletterRequest $request
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function unsubscribeNewsletter(UnsubscribeNewsletterRequest $request): \Illuminate\Contracts\View\View
|
||||
{
|
||||
$error = null;
|
||||
$hashcode = $request->hashcode;
|
||||
|
||||
try {
|
||||
SingleOptin::unsetStatusWithHashcode($hashcode);
|
||||
} catch (ApiErrorException $e) {
|
||||
Log::debug($e->getMessage());
|
||||
if ($e->getApiError()->equals(ApiError::modelNotFound)) {
|
||||
abort(404);
|
||||
} else {
|
||||
if (app()->bound('sentry')) {
|
||||
app('sentry')->captureException($e);
|
||||
}
|
||||
$error = true;
|
||||
}
|
||||
} catch (CrmException $e) {
|
||||
Log::debug($e->getMessage());
|
||||
$error = true;
|
||||
if (app()->bound('sentry')) {
|
||||
app('sentry')->captureException($e);
|
||||
}
|
||||
} //end try
|
||||
|
||||
if (!is_null($error)) {
|
||||
return view('fo.pages.newsletter-unsubscribe')->with(
|
||||
'error',
|
||||
trans('Une erreur est survenue, merci de réessayer ultérieurement')
|
||||
);
|
||||
}
|
||||
return view('fo.pages.newsletter-unsubscribe');
|
||||
return view('fo.pages.home', compact('slides', 'ranges', 'threeproducts', 'events', 'news'));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ class IdeasController extends Controller
|
|||
*
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function index(): \Illuminate\Contracts\View\View
|
||||
public function index()
|
||||
{
|
||||
return view('fo.pages.ideas.ideas');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ namespace App\Http\Controllers\Fo;
|
|||
use App\Http\Controllers\Controller;
|
||||
use App\Models\News;
|
||||
use App\Models\NewsCategory;
|
||||
use Illuminate\Contracts\Database\Eloquent\Builder;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class NewsController extends Controller
|
||||
|
|
@ -16,42 +15,43 @@ class NewsController extends Controller
|
|||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function index(Request $request): \Illuminate\Contracts\View\View
|
||||
public function index(Request $request)
|
||||
{
|
||||
// Get NewsCategories.
|
||||
$categories = NewsCategory::query()->orderBy('label', 'ASC')->get();
|
||||
$categories = NewsCategory::orderBy('label', 'ASC')->get();
|
||||
|
||||
// Get News.
|
||||
$filters_activated = collect($request->input('filtered_categorie'));
|
||||
$filters_activated = $request->filtered_categorie;
|
||||
|
||||
$news = News::query()->with('categories')->when(
|
||||
$filters_activated->first() !== 'all',
|
||||
fn(Builder $q) => $q->with('categories')
|
||||
->whereRelation('categories', fn(Builder $q) =>
|
||||
$q->where(function (Builder $q) use ($filters_activated) {
|
||||
$news = News::when(
|
||||
isset($filters_activated) and $filters_activated[0] != 'all',
|
||||
function ($query) use ($filters_activated) {
|
||||
$query->with('categories')
|
||||
->whereRelation('categories', function ($query) use ($filters_activated) {
|
||||
foreach ($filters_activated as $value) {
|
||||
if (is_string($value)) {
|
||||
$q->orWhere('id', $value);
|
||||
}
|
||||
$query->orWhere('id', 'like', $value);
|
||||
}
|
||||
}))
|
||||
)->where('published', true)->orderByDesc('created_at')->paginate(6);
|
||||
});
|
||||
}
|
||||
)
|
||||
->where('status', true)
|
||||
->orderBy('created_at')
|
||||
->paginate(6);
|
||||
|
||||
return view('fo.pages.news.index', compact('categories', 'news', 'filters_activated'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show resource
|
||||
*
|
||||
* @param \App\Models\News $news
|
||||
* Undocumented function
|
||||
* @param News $news
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function show(News $news): \Illuminate\Contracts\View\View
|
||||
public function show(News $news)
|
||||
{
|
||||
$news->load('categories', 'news.categories', 'products');
|
||||
$readingTime = $news->getReadingTime();
|
||||
$products = $news->products()->with(['subrange', 'subrange.range'])->get();
|
||||
$products = $news->products()->get();
|
||||
|
||||
return view('fo.pages.news.post', compact('news', 'readingTime', 'products'));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,10 +11,11 @@ use App\Http\Resources\Fo\Products\ProductResource;
|
|||
use App\Models\Product;
|
||||
use App\Models\Range;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use Illuminate\Support\Str;
|
||||
use Mccarlosen\LaravelMpdf\LaravelMpdf;
|
||||
|
||||
class ProductsController extends Controller
|
||||
{
|
||||
|
|
@ -23,7 +24,7 @@ class ProductsController extends Controller
|
|||
*
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function index(): \Illuminate\Contracts\View\View
|
||||
public function index()
|
||||
{
|
||||
// Gammes.
|
||||
$ranges = Range::all();
|
||||
|
|
@ -35,9 +36,9 @@ class ProductsController extends Controller
|
|||
* View a specific range products
|
||||
*
|
||||
* @param \App\Models\Range $range
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
* @return \Illuminate\Contracts\View\View|\Illuminate\Contracts\View\Factory
|
||||
*/
|
||||
public function products(Range $range): \Illuminate\Contracts\View\View
|
||||
public function products(Range $range)
|
||||
{
|
||||
$ranges = Range::query()->with('subranges')->get();
|
||||
$range->load('subranges');
|
||||
|
|
@ -53,16 +54,15 @@ class ProductsController extends Controller
|
|||
*
|
||||
* @param \App\Http\Requests\Fo\Products\AjaxFilterProductsRequest $request
|
||||
* @param \App\Models\Range $range
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
* @return \Illuminate\Contracts\View\View|\Illuminate\Contracts\View\Factory
|
||||
*/
|
||||
public function productsAjax(AjaxFilterProductsRequest $request, Range $range): \Illuminate\Http\JsonResponse
|
||||
public function productsAjax(AjaxFilterProductsRequest $request, Range $range)
|
||||
{
|
||||
// * Init product query with search and status.
|
||||
$search = htmlspecialchars($request->query('search') ?? '');
|
||||
$productsQuery = !empty($search) ? $this->getProductQuery($search) : Product::query();
|
||||
$productsQuery->with('subrange.range');
|
||||
$productsQuery->where('published', true);
|
||||
$productsQuery->orderBy('priority_order', 'ASC');
|
||||
$productsQuery->where('status', true);
|
||||
|
||||
// * Range filter (obligatoire).
|
||||
$productsQuery->whereHas('subrange', function (Builder $q) use ($range) {
|
||||
|
|
@ -72,7 +72,7 @@ class ProductsController extends Controller
|
|||
});
|
||||
|
||||
// * Subrange filter.
|
||||
if (count($request->subranges) > 0) {
|
||||
if (count($request->subranges)) {
|
||||
$productsQuery->whereHas('subrange', function (Builder $q) use ($request, $range) {
|
||||
$q->whereIn('id', $request->subranges);
|
||||
$q->whereHas('range', function (Builder $q) use ($range) {
|
||||
|
|
@ -85,6 +85,7 @@ class ProductsController extends Controller
|
|||
if ($request->vip) {
|
||||
$productsQuery->where('is_vip', $request->vip);
|
||||
}
|
||||
|
||||
return \response()->json(new ProductPaginatedCollectionResource($productsQuery->paginate(6)));
|
||||
}
|
||||
|
||||
|
|
@ -92,17 +93,17 @@ class ProductsController extends Controller
|
|||
* View a specific range products
|
||||
*
|
||||
* @param \App\Models\Product $publishedProduct
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
* @return \Illuminate\Contracts\View\View|\Illuminate\Contracts\View\Factory
|
||||
*/
|
||||
public function show(Product $publishedProduct): \Illuminate\Contracts\View\View
|
||||
public function show(Product $publishedProduct)
|
||||
{
|
||||
/** @var \Illuminate\Database\Eloquent\Collection<\App\Models\Advice> */
|
||||
$recipes = $publishedProduct->recipesQuery()->where('published', true)->with('tags')->get();
|
||||
$recipes = $publishedProduct->recipesQuery()->where('status', true)->get();
|
||||
/** @var \Illuminate\Database\Eloquent\Collection<\App\Models\Advice> */
|
||||
$tips = $publishedProduct->tipsQuery()->where('published', true)->get();
|
||||
$tips = $publishedProduct->tipsQuery()->where('status', true)->get();
|
||||
|
||||
// Force load subrange and range.
|
||||
$publishedProduct->load(['subrange.range', 'tags']);
|
||||
$publishedProduct->load('subrange.range');
|
||||
|
||||
/** @var \App\Models\Subrange */
|
||||
$subrange = $publishedProduct->subrange;
|
||||
|
|
@ -111,9 +112,8 @@ class ProductsController extends Controller
|
|||
|
||||
/** @var \Illuminate\Database\Eloquent\Collection<\App\Models\Product> */
|
||||
$randomProducts = Product::query()
|
||||
->with('subrange.range')
|
||||
->where('id', '!=', $publishedProduct->id)
|
||||
->where('published', true)
|
||||
->where('status', true)
|
||||
->whereHas('subrange', function (Builder $q) use ($range) {
|
||||
$q->whereHas('range', function (Builder $q) use ($range) {
|
||||
$q->where('id', $range->id);
|
||||
|
|
@ -122,48 +122,27 @@ class ProductsController extends Controller
|
|||
|
||||
$product = $publishedProduct;
|
||||
|
||||
return view('fo.pages.products.product', compact(
|
||||
'product',
|
||||
'recipes',
|
||||
'tips',
|
||||
'randomProducts'
|
||||
));
|
||||
return view('fo.pages.products.product', compact('product', 'recipes', 'tips', 'randomProducts'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Print product commercial sheet
|
||||
*
|
||||
* @param \App\Models\Product $publishedProduct
|
||||
* @return \Illuminate\Http\Response
|
||||
* @return \Illuminate\Contracts\View\View|\Illuminate\Contracts\View\Factory
|
||||
*/
|
||||
public function printCommercialSheet(Product $publishedProduct): Response
|
||||
public function printCommericalSheet(Product $publishedProduct)
|
||||
{
|
||||
$title = trans('Fiche commerciale du produit : :label - :appname', [
|
||||
'label' => $publishedProduct->label,
|
||||
'appname' => \config('app.name', 'Le Gaulois Pro')
|
||||
]);
|
||||
$filename = trans('fiche-commerciale-:slug-:date.pdf', [
|
||||
$filename = trans('fiche-commerciale-:slug-:date', [
|
||||
'slug' => Str::slug($publishedProduct->label),
|
||||
'date' => \now()->format('Y-m-d')
|
||||
]);
|
||||
|
||||
/**
|
||||
* ! Réponse mano car enfait \Mccarlosen\LaravelMpdf\LaravelMpdf
|
||||
* ! ne retourne pas vraiemnt une http response, mais provoque une 500
|
||||
* ! apres avoir header et echo dans le corps de la réponse php (Nasty trick)
|
||||
*/
|
||||
return \response(
|
||||
$this->generateProductCommercialPdf($publishedProduct, $title)->download($filename),
|
||||
200,
|
||||
[
|
||||
'Content-Type' => 'application/pdf',
|
||||
'Content-disposition' => "inline; filename=\"{$filename}\"",
|
||||
'Cache-Control' => 'public, must-revalidate, max-age=0',
|
||||
'Pragma' => 'public',
|
||||
'Expires' => 'Sat, 26 Jul 1997 05:00:00 GMT',
|
||||
'Last-Modified' => gmdate('D, d M Y H:i:s') . ' GMT',
|
||||
]
|
||||
);
|
||||
return $this->generateProductCommercialPdf($publishedProduct, $title)
|
||||
->stream("{$filename}.pdf");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -173,10 +152,8 @@ class ProductsController extends Controller
|
|||
* @param \App\Models\Product $publishedProduct
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function addProductToBasket(
|
||||
AjaxAddProductBasket $request,
|
||||
Product $publishedProduct
|
||||
): \Illuminate\Http\JsonResponse {
|
||||
public function addProductToBasket(AjaxAddProductBasket $request, Product $publishedProduct): JsonResponse
|
||||
{
|
||||
$sessionProducts = $this->getBasketProducts();
|
||||
$sessionProducts->put(
|
||||
$publishedProduct->id,
|
||||
|
|
@ -198,7 +175,7 @@ class ProductsController extends Controller
|
|||
* @param string $slug
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function removeProductFromBasket(string $slug): \Illuminate\Http\JsonResponse
|
||||
public function removeProductFromBasket(string $slug): JsonResponse
|
||||
{
|
||||
$sessionProducts = $this->getBasketProducts()->filter(function (array $basketElement) use ($slug) {
|
||||
return $basketElement['product']->slug !== $slug and !empty($slug);
|
||||
|
|
@ -232,13 +209,13 @@ class ProductsController extends Controller
|
|||
* @param string $title
|
||||
* @return \Mccarlosen\LaravelMpdf\LaravelMpdf
|
||||
*/
|
||||
private function generateProductCommercialPdf(Product $product, string $title): \Mccarlosen\LaravelMpdf\LaravelMpdf
|
||||
private function generateProductCommercialPdf(Product $product, string $title): LaravelMpdf
|
||||
{
|
||||
/** @var \Mccarlosen\LaravelMpdf\LaravelMpdfWrapper */
|
||||
/** @var \Mccarlosen\LaravelMpdf\LaravelMpdf */
|
||||
$mpdf = app('laravel-mpdf');
|
||||
/** @var \Mccarlosen\LaravelMpdf\LaravelMpdf */
|
||||
$pdf = $mpdf->loadView(
|
||||
'fo.documents.product-commercial-sheet',
|
||||
'documents.product-commercial-sheet',
|
||||
// * Dirty convert to object.
|
||||
[
|
||||
'title' => $title,
|
||||
|
|
@ -260,6 +237,7 @@ class ProductsController extends Controller
|
|||
'margin_bottom' => 0,
|
||||
'margin_header' => 0,
|
||||
'margin_footer' => 0,
|
||||
'margin_top' => 0,
|
||||
'orientation' => 'P',
|
||||
'title' => $title,
|
||||
'author' => \config('app.name', 'Le Gaulois Pro'),
|
||||
|
|
|
|||
|
|
@ -7,9 +7,7 @@ use App\Enums\Advices\AdviceTypeEnum;
|
|||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Advice;
|
||||
use App\Models\Range;
|
||||
use Illuminate\Contracts\Database\Eloquent\Builder;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
class RecipesController extends Controller
|
||||
{
|
||||
|
|
@ -19,63 +17,37 @@ class RecipesController extends Controller
|
|||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function indexRecipes(Request $request): \Illuminate\Contracts\View\View
|
||||
public function indexRecipes(Request $request)
|
||||
{
|
||||
/** @var string|null */
|
||||
$search_range = $request->input('search_range');
|
||||
/** @var string|null */
|
||||
$search_cooking_time = $request->input('search_cooking_time');
|
||||
/** @var string|null */
|
||||
$search_preparation_time = $request->input('search_preparation_time');
|
||||
$search_range = $request->search_range;
|
||||
$search_cooking_time = $request->search_cooking_time;
|
||||
$search_preparation_time = $request->search_preparation_time;
|
||||
|
||||
/** @var array<\App\Enums\Advices\AdviceTimeEnum> */
|
||||
$adviceEnumList = AdviceTimeEnum::all();
|
||||
$ranges = Range::all();
|
||||
$ranges = Range::all();
|
||||
$query = Advice::where('type', 1)->where('status', true)
|
||||
->when(is_numeric($search_range), function ($query) use ($search_range) {
|
||||
$query->whereHas('products', function ($query) use ($search_range) {
|
||||
$query->whereHas('subrange', function ($query) use ($search_range) {
|
||||
$query->whereHas('range', function ($query) use ($search_range) {
|
||||
$query->where('id', 'LIKE', $search_range);
|
||||
});
|
||||
});
|
||||
});
|
||||
})
|
||||
->when(is_numeric($search_cooking_time), function ($query) use ($search_cooking_time) {
|
||||
$query->whereBetween('cooking_time', [
|
||||
AdviceTimeEnum::toArray()[$search_cooking_time - 1]->times[0],
|
||||
AdviceTimeEnum::toArray()[$search_cooking_time - 1]->times[1]
|
||||
]);
|
||||
})
|
||||
->when(is_numeric($search_preparation_time), function ($query) use ($search_preparation_time) {
|
||||
$query->whereBetween('preparation_time', [
|
||||
AdviceTimeEnum::toArray()[$search_preparation_time - 1]->times[0],
|
||||
AdviceTimeEnum::toArray()[$search_preparation_time - 1]->times[1]
|
||||
]);
|
||||
});
|
||||
|
||||
$cooking_time = null;
|
||||
if (is_numeric($search_cooking_time)) {
|
||||
$cooking_time = Arr::get($adviceEnumList, $search_cooking_time - 1);
|
||||
}
|
||||
$preparation_time = null;
|
||||
if (is_numeric($search_preparation_time)) {
|
||||
$preparation_time = Arr::get($adviceEnumList, $search_preparation_time - 1);
|
||||
}
|
||||
/** @var \App\Enums\Advices\AdviceTimeEnum|null $cooking_time */
|
||||
/** @var \App\Enums\Advices\AdviceTimeEnum|null $preparation_time */
|
||||
|
||||
$query = Advice::query()->with('tags')->where('type', 1)->where('published', true)->when(
|
||||
is_numeric($search_range),
|
||||
fn(Builder $q) =>
|
||||
$q->whereHas(
|
||||
'products',
|
||||
fn(Builder $q) =>
|
||||
$q->whereHas(
|
||||
'subrange',
|
||||
fn(Builder $q) =>
|
||||
$q->whereHas(
|
||||
'range',
|
||||
fn(Builder $q) =>
|
||||
$q->where('id', 'LIKE', $search_range)
|
||||
)
|
||||
)
|
||||
)
|
||||
)->when(
|
||||
$cooking_time,
|
||||
fn(Builder $q) =>
|
||||
$q->whereBetween('cooking_time', [
|
||||
Arr::get($cooking_time->times(), 0),
|
||||
Arr::get($cooking_time->times(), 1)
|
||||
])
|
||||
)->when(
|
||||
$preparation_time,
|
||||
fn(Builder $q) =>
|
||||
$q->whereBetween('preparation_time', [
|
||||
Arr::get($preparation_time->times(), 0),
|
||||
Arr::get($preparation_time->times(), 1)
|
||||
])
|
||||
);
|
||||
|
||||
$recipes = $query->orderBy('priority_order', 'ASC')->paginate(9);
|
||||
$recipes = $query->orderBy('slug', 'ASC')->paginate(9);
|
||||
|
||||
return view('fo.pages.ideas.recipes', compact(
|
||||
'ranges',
|
||||
|
|
@ -92,11 +64,11 @@ class RecipesController extends Controller
|
|||
* @param \App\Models\Advice $publishedAdvice
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function show(Advice $publishedAdvice): \Illuminate\Contracts\View\View
|
||||
public function show(Advice $publishedAdvice)
|
||||
{
|
||||
$recipe = $publishedAdvice;
|
||||
$relatedRecipes = $publishedAdvice->advices()->where('type', '=', AdviceTypeEnum::recipes->value())->get();
|
||||
$relatedTips = $publishedAdvice->advices()->where('type', '=', AdviceTypeEnum::tips->value())->get();
|
||||
$relatedRecipes = $publishedAdvice->advices()->where('type', '=', AdviceTypeEnum::recipes()->value)->get();
|
||||
$relatedTips = $publishedAdvice->advices()->where('type', '=', AdviceTypeEnum::tips()->value)->get();
|
||||
|
||||
return view('fo.pages.ideas.recipe', compact('recipe', 'relatedRecipes', 'relatedTips'));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,10 +11,10 @@ class SearchController extends Controller
|
|||
/**
|
||||
* Search input txt in products, news and recipes
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function search(Request $request): \Illuminate\Contracts\View\View
|
||||
public function search(Request $request)
|
||||
{
|
||||
$search = htmlspecialchars($request->query('search') ?? '');
|
||||
$model = $request->query('model');
|
||||
|
|
@ -25,8 +25,11 @@ class SearchController extends Controller
|
|||
$recipes = [];
|
||||
$recipesTotal = 0;
|
||||
|
||||
if (is_array($search)) {
|
||||
abort(400);
|
||||
}
|
||||
if (is_string($model)) {
|
||||
return $this->searchModel($model, $search);
|
||||
return $this->callAction('searchModel', [$model, $search]);
|
||||
}
|
||||
|
||||
if (!empty($search)) {
|
||||
|
|
@ -60,9 +63,9 @@ class SearchController extends Controller
|
|||
*
|
||||
* @param string $modelName
|
||||
* @param string $search
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function searchModel(string $modelName, string $search): \Illuminate\Contracts\View\View
|
||||
public function searchModel(string $modelName, string $search)
|
||||
{
|
||||
$models = [];
|
||||
$modelList = [
|
||||
|
|
|
|||
|
|
@ -1,48 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Fo;
|
||||
|
||||
use App\Enums\StaticPageType;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\StaticPage;
|
||||
use Uwil\SitemapGenerator\Lib\SitemapHelper;
|
||||
|
||||
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)->first();
|
||||
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)->first();
|
||||
return view('fo.pages.legals', ['staticPageModel' => $policiesPage]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sitemap show
|
||||
*
|
||||
* @param \App\Models\StaticPage $sitemap
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function sitemap(StaticPage $sitemap)
|
||||
{
|
||||
$sitemap = StaticPage::query()->where('type', StaticPageType::sitemap)->first();
|
||||
$singlePages = SitemapHelper::getSinglePages();
|
||||
return view('fo.pages.sitemap', ['staticPageModel' => $sitemap, 'singlePages' => $singlePages]);
|
||||
}
|
||||
}
|
||||
18
app/Http/Controllers/Fo/StoryController.php
Normal file
18
app/Http/Controllers/Fo/StoryController.php
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Fo;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
class StoryController extends Controller
|
||||
{
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return view('fo.pages.story');
|
||||
}
|
||||
}
|
||||
|
|
@ -13,11 +13,11 @@ class TipsController extends Controller
|
|||
*
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function indexTips(): \Illuminate\Contracts\View\View
|
||||
public function indexTips()
|
||||
{
|
||||
$advices = Advice::query()->with('tags')
|
||||
->where('type', AdviceTypeEnum::tips)
|
||||
->where('published', true)
|
||||
->where('type', AdviceTypeEnum::tips())
|
||||
->where('status', true)
|
||||
->paginate(9);
|
||||
return view('fo.pages.ideas.tips', \compact('advices'));
|
||||
}
|
||||
|
|
@ -26,14 +26,12 @@ class TipsController extends Controller
|
|||
* Display an advice
|
||||
*
|
||||
* @param \App\Models\Advice $publishedAdvice
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
* @return \Illuminate\Contracts\View\View|\Illuminate\Contracts\View\Factory
|
||||
*/
|
||||
public function show(Advice $publishedAdvice): \Illuminate\Contracts\View\View
|
||||
public function show(Advice $publishedAdvice)
|
||||
{
|
||||
$publishedAdvice->load([
|
||||
'advices',
|
||||
'products.subrange.range',
|
||||
'tags'
|
||||
'advices', 'products.subrange', 'tags'
|
||||
]);
|
||||
return view('fo.pages.ideas.tip', [
|
||||
'adviceModel' => $publishedAdvice
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ class Kernel extends HttpKernel
|
|||
protected $middleware = [
|
||||
\App\Http\Middleware\TrustHosts::class,
|
||||
\App\Http\Middleware\TrustProxies::class,
|
||||
\Fruitcake\Cors\HandleCors::class,
|
||||
\App\Http\Middleware\PreventRequestsDuringMaintenance::class,
|
||||
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
|
||||
\App\Http\Middleware\TrimStrings::class,
|
||||
|
|
@ -33,16 +34,12 @@ class Kernel extends HttpKernel
|
|||
\App\Http\Middleware\EncryptCookies::class,
|
||||
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
|
||||
\Illuminate\Session\Middleware\StartSession::class,
|
||||
\Illuminate\Session\Middleware\AuthenticateSession::class,
|
||||
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
|
||||
\App\Http\Middleware\VerifyCsrfToken::class,
|
||||
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||
\App\Http\Middleware\SecureHeaders::class
|
||||
],
|
||||
'saml' => [
|
||||
\App\Http\Middleware\EncryptCookies::class,
|
||||
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
|
||||
\Illuminate\Session\Middleware\StartSession::class,
|
||||
],
|
||||
]
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Auth\Middleware\Authenticate as Middleware;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
|
||||
class Authenticate extends Middleware
|
||||
|
|
@ -13,8 +12,9 @@ class Authenticate extends Middleware
|
|||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return string|null
|
||||
* @phpcs:disable Squiz.Commenting.FunctionComment.TypeHintMissing
|
||||
*/
|
||||
protected function redirectTo(Request $request): ?string
|
||||
protected function redirectTo($request)
|
||||
{
|
||||
$logins = [
|
||||
'backend' => route('bo.login')
|
||||
|
|
@ -31,9 +31,8 @@ class Authenticate extends Middleware
|
|||
}
|
||||
}
|
||||
}
|
||||
return route('login');
|
||||
return collect($logins)->first() ?? '/';
|
||||
}
|
||||
|
||||
return null;
|
||||
abort(401);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,5 +11,6 @@ class EncryptCookies extends Middleware
|
|||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $except = [];
|
||||
protected $except = [
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ namespace App\Http\Middleware;
|
|||
|
||||
use App\Lib\Helpers\ToolboxHelper;
|
||||
use Illuminate\Http\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class HtmlSanitizer
|
||||
{
|
||||
|
|
@ -13,34 +12,21 @@ class HtmlSanitizer
|
|||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @param string|array ...$params
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
* @param mixed ...$params
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle(Request $request, \Closure $next, string|array ...$params): Response
|
||||
public function handle(Request $request, \Closure $next, ...$params)
|
||||
{
|
||||
$inputs = $request->all();
|
||||
/** @var callable|null */
|
||||
$cleanInput = null;
|
||||
$cleanInput = function (
|
||||
null|string|array &$input,
|
||||
string $name,
|
||||
?string $rootName = null
|
||||
) use (
|
||||
$params,
|
||||
&$cleanInput
|
||||
): void {
|
||||
// * Nested element array
|
||||
if (is_array($input)) {
|
||||
array_walk_recursive($input, $cleanInput, $name);
|
||||
}
|
||||
array_walk_recursive($inputs, function (&$input, $name) use ($params) {
|
||||
if (!is_string($input)) {
|
||||
return;
|
||||
}
|
||||
if (in_array($name, $params) or in_array($rootName ?? $name, $params)) {
|
||||
if (in_array($name, $params)) {
|
||||
// ? Is a json input ?
|
||||
if ($isJson = \json_decode($input, true) and is_array($isJson)) {
|
||||
// ! Decode each json field recursive.
|
||||
\array_walk_recursive($isJson, function (string|array &$item) {
|
||||
\array_walk_recursive($isJson, function (&$item) {
|
||||
if (\is_string($item)) {
|
||||
$item = clean($item);
|
||||
$item = ToolboxHelper::stripCkEditorSchemesOnMediaInputs($item);
|
||||
|
|
@ -53,8 +39,7 @@ class HtmlSanitizer
|
|||
} else {
|
||||
$input = strip_tags($input);
|
||||
}
|
||||
};
|
||||
\array_walk($inputs, $cleanInput);
|
||||
});
|
||||
$request->merge($inputs);
|
||||
return $next($request);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,5 +11,6 @@ class PreventRequestsDuringMaintenance extends Middleware
|
|||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $except = [];
|
||||
protected $except = [
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,38 +4,27 @@ namespace App\Http\Middleware;
|
|||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class RedirectIfAuthenticated
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
|
||||
* @param string|null ...$guards
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
* @throws \RuntimeException If guard is unhandled.
|
||||
* @phpcs:disable Squiz.Commenting.FunctionComment.IncorrectTypeHint
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @param string|null ...$guards
|
||||
* @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function handle(Request $request, \Closure $next, ...$guards): Response
|
||||
public function handle(Request $request, \Closure $next, ...$guards)
|
||||
{
|
||||
// phpcs:enable phpcs:disable
|
||||
$logins = [
|
||||
'backend' => route('bo.dashboard')
|
||||
];
|
||||
$guards = empty($guards) ? [null] : $guards;
|
||||
|
||||
foreach ($guards as $guard) {
|
||||
if (Auth::guard($guard)->check()) {
|
||||
switch ($guard) {
|
||||
case 'frontend':
|
||||
return \redirect()->route('fo.home');
|
||||
case 'backend':
|
||||
if (!$request->routeIs('bo.*')) {
|
||||
continue;
|
||||
}
|
||||
return \redirect()->route('bo.dashboard');
|
||||
default:
|
||||
throw new \RuntimeException("Unhandled guard `{$guard}` .");
|
||||
}
|
||||
return \redirect()->to($logins[$guard]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,8 +6,6 @@ use Closure;
|
|||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Illuminate\Support\Facades\View;
|
||||
use Illuminate\Support\Facades\Vite;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class SecureHeaders
|
||||
{
|
||||
|
|
@ -26,21 +24,17 @@ class SecureHeaders
|
|||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
* @phpcs:disable Squiz.Commenting.FunctionComment.IncorrectTypeHint
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function handle(Request $request, Closure $next): Response
|
||||
public function handle(Request $request, Closure $next)
|
||||
{
|
||||
// phpcs:enable
|
||||
// * For Vite DEV
|
||||
$host = \parse_url(\config('app.url'), \PHP_URL_HOST);
|
||||
View::share('nonce', $nonce = Vite::useCspNonce());
|
||||
View::share('nonce', $nonce = \uniqid());
|
||||
// * For VueJS dev tool to execute
|
||||
$jsDev = config('app.debug') ? "'unsafe-eval' 'unsafe-inline'" : "'nonce-{$nonce}' 'strict-dynamic'";
|
||||
$jsDev = config('app.debug') ? "'unsafe-eval' 'unsafe-inline'" : "'nonce-$nonce'";
|
||||
$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);
|
||||
$response = $next($request);
|
||||
$response->headers->set('Referrer-Policy', 'no-referrer-when-downgrade');
|
||||
|
|
@ -52,58 +46,29 @@ class SecureHeaders
|
|||
"default-src 'none';",
|
||||
"manifest-src 'self';",
|
||||
// * CKEDITOR Specific https://ckeditor.com/docs/ckeditor5/latest/installation/advanced/csp.html
|
||||
"connect-src 'self' blob: " . implode(' ', [
|
||||
// * VITE DEV
|
||||
config('app.debug') ? "wss://{$host}:4443" : '',
|
||||
config('app.debug') ? "https://{$host}:4443" : '',
|
||||
'https://yl.s-web.fr'
|
||||
]) . ';',
|
||||
"img-src 'self' data: blob: " . implode(' ', [
|
||||
'https://yl.s-web.fr',
|
||||
'https://i3.ytimg.com/',
|
||||
// * VITE DEV
|
||||
config('app.debug') ? "https://{$host}:4443" : '',
|
||||
// * MESBR
|
||||
'https://dev.mesbr.eu',
|
||||
'https://www.mesbr.eu'
|
||||
]) . ';',
|
||||
"object-src 'self' " . implode(' ', []) . ';',
|
||||
"frame-src 'self' " . implode(' ', [
|
||||
"connect-src 'self' https://yl.s-web.fr blob:;",
|
||||
"img-src * https://yl.s-web.fr data: blob:;",
|
||||
// ! Blob required for printjs
|
||||
'frame-src ' . implode(" ", [
|
||||
'https://www.youtube-nocookie.com',
|
||||
'https://www.google.com/recaptcha/',
|
||||
'https://recaptcha.google.com/recaptcha/',
|
||||
'https://www.google.com/maps/',
|
||||
'blob:'
|
||||
]) . ';',
|
||||
"font-src 'self' data: " . \implode(' ', [
|
||||
// * VITE DEV
|
||||
config('app.debug') ? "https://{$host}:4443" : '',
|
||||
'https://fonts.gstatic.com;'
|
||||
]) . ';',
|
||||
"font-src 'self' data:;",
|
||||
// ! Using CKEditor will must have unsafe-inline style
|
||||
// phpcs:ignore Generic.Files.LineLength.TooLong
|
||||
"style-src 'self' 'unsafe-inline' " . \implode(' ', [
|
||||
'https://cdnjs.cloudflare.com',
|
||||
// * File Manager
|
||||
'https://fonts.googleapis.com',
|
||||
'https://cdn.jsdelivr.net',
|
||||
'https://use.fontawesome.com',
|
||||
'https://fonts.googleapis.com',
|
||||
// * VITE DEV
|
||||
config('app.debug') ? "https://{$host}:4443" : '',
|
||||
]) . ';',
|
||||
"style-src 'self' 'unsafe-inline';",
|
||||
// ! If you dont use ckeditor use this
|
||||
// "style-src 'self' 'nonce-$nonce';",
|
||||
// phpcs:ignore Generic.Files.LineLength.TooLong
|
||||
"script-src 'self' {$jsDev} " . \implode(' ', [
|
||||
'https: blob:',
|
||||
'https://www.googletagmanager.com',
|
||||
'https://cdnjs.cloudflare.com',
|
||||
// * VITE DEV
|
||||
config('app.debug') ? "https://{$host}:4443" : '',
|
||||
]) . ';'
|
||||
'script-src ' . implode(" ", [
|
||||
'\'self\'',
|
||||
'https://www.google.com/recaptcha/',
|
||||
'https://www.gstatic.com/recaptcha/',
|
||||
'https://yl.s-web.fr',
|
||||
]) . ' ' . $jsDev . ';'
|
||||
];
|
||||
|
||||
$response->headers->set(
|
||||
'Content-Security-Policy',
|
||||
implode(' ', $cspPolicies) . $reportUri
|
||||
|
|
@ -118,7 +83,7 @@ class SecureHeaders
|
|||
* @param array $headerList
|
||||
* @return void
|
||||
*/
|
||||
private function removeUnwantedHeaders(array $headerList): void
|
||||
private function removeUnwantedHeaders(array $headerList)
|
||||
{
|
||||
foreach ($headerList as $header) {
|
||||
header_remove($header);
|
||||
|
|
|
|||
|
|
@ -1,15 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Routing\Middleware\ValidateSignature as Middleware;
|
||||
|
||||
class ValidateSignature extends Middleware
|
||||
{
|
||||
/**
|
||||
* The names of the query string parameters that should be ignored.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $except = [];
|
||||
}
|
||||
|
|
@ -12,6 +12,5 @@ class VerifyCsrfToken extends Middleware
|
|||
* @var array<int, string>
|
||||
*/
|
||||
protected $except = [
|
||||
'/csp-report'
|
||||
];
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,12 +4,11 @@ namespace App\Http\Requests\Bo\Advice;
|
|||
|
||||
use App\Enums\Advices\AdviceDifficultyEnum;
|
||||
use App\Enums\Advices\AdviceTypeEnum;
|
||||
use App\Rules\WysiwygLength;
|
||||
use App\Traits\Requests\HasPicture;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Validation\Rules\Enum;
|
||||
use Kwaadpepper\Enum\Rules\EnumIsValidRule;
|
||||
|
||||
class StoreAdviceRequest extends FormRequest
|
||||
{
|
||||
|
|
@ -20,7 +19,7 @@ class StoreAdviceRequest extends FormRequest
|
|||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function authorize(): bool
|
||||
public function authorize()
|
||||
{
|
||||
return auth('backend')->check();
|
||||
}
|
||||
|
|
@ -29,29 +28,28 @@ class StoreAdviceRequest extends FormRequest
|
|||
* Prepare the data for validation.
|
||||
*
|
||||
* @return void
|
||||
* @phpcs:disable Generic.Metrics.CyclomaticComplexity.TooHigh, Squiz.Commenting.FunctionComment.Missing
|
||||
*/
|
||||
protected function prepareForValidation(): void
|
||||
// phpcs:ignore Generic.Metrics.CyclomaticComplexity.TooHigh, Squiz.Commenting.FunctionComment.Missing
|
||||
protected function prepareForValidation()
|
||||
{
|
||||
//phpcs:enable
|
||||
$this->merge([
|
||||
'slug' => Str::slug(strip_tags($this->input('title'))),
|
||||
'published' => $this->boolean('published'),
|
||||
'tags' => $this->input('tags', []),
|
||||
'products' => $this->input('products', []),
|
||||
'associated_tips_list' => $this->input('associated_tips_list', []),
|
||||
'associated_recipes_list' => $this->input('associated_recipes_list', []),
|
||||
'slug' => Str::slug(strip_tags($this->title)),
|
||||
'status' => $this->status ? true : false,
|
||||
'tags' => $this->tags ?? [],
|
||||
'products' => $this->products ?? [],
|
||||
'associated_tips_list' => $this->associated_tips_list ?? [],
|
||||
'associated_recipes_list' => $this->associated_recipes_list ?? [],
|
||||
// * For sync relations
|
||||
'tags_list' => \collect($this->input('tags'))->map(function ($value) {
|
||||
'tags_list' => \collect($this->tags)->map(function ($value) {
|
||||
return \is_array($value) ? ($value['value'] ?? null) : null;
|
||||
})->filter()->all(),
|
||||
'products_list' => \collect($this->input('products'))->map(function ($value) {
|
||||
'products_list' => \collect($this->products)->map(function ($value) {
|
||||
return \is_array($value) ? ($value['value'] ?? null) : null;
|
||||
})->filter()->all(),
|
||||
'tips_list' => \collect($this->input('tips'))->map(function ($value) {
|
||||
'tips_list' => \collect($this->associated_tips_list)->map(function ($value) {
|
||||
return \is_array($value) ? ($value['value'] ?? null) : null;
|
||||
})->filter()->all(),
|
||||
'recipes_list' => \collect($this->input('recipes'))->map(function ($value) {
|
||||
'recipes_list' => \collect($this->associated_recipes_list)->map(function ($value) {
|
||||
return \is_array($value) ? ($value['value'] ?? null) : null;
|
||||
})->filter()->all(),
|
||||
]);
|
||||
|
|
@ -64,51 +62,40 @@ class StoreAdviceRequest extends FormRequest
|
|||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
* @phpcs:disable Generic.Metrics.CyclomaticComplexity.TooHigh, Squiz.Commenting.FunctionComment.Missing
|
||||
*/
|
||||
public function rules(): array
|
||||
// phpcs:ignore Generic.Metrics.CyclomaticComplexity.TooHigh, Squiz.Commenting.FunctionComment.Missing
|
||||
public function rules()
|
||||
{
|
||||
//phpcs:enable
|
||||
$rules = [
|
||||
'title' => 'required|min:3|max:255',
|
||||
'seo_title' => 'required|min:45|max:70',
|
||||
'seo_description' => 'required|min:50|max:160',
|
||||
'type' => ['required', new Enum(AdviceTypeEnum::class)],
|
||||
'picture_alt' => 'required_with:picture|nullable|min:3|max:255',
|
||||
'picture_title' => 'required_with:picture|nullable|min:3|max:255',
|
||||
'sticker_alt' => 'required_with:sticker|nullable|min:3|max:255',
|
||||
'sticker_title' => 'required_with:sticker|nullable|min:3|max:255',
|
||||
'sticker_sm_alt' => 'required_with:sticker_sm|nullable|min:3|max:255',
|
||||
'sticker_sm_title' => 'required_with:sticker_sm|nullable|min:3|max:255',
|
||||
'preparation' => [
|
||||
'required',
|
||||
'string',
|
||||
new WysiwygLength(15, 2500)
|
||||
],
|
||||
'advice' => [
|
||||
'nullable',
|
||||
'string',
|
||||
new WysiwygLength(15, 2500)
|
||||
],
|
||||
'ingredients' => [
|
||||
'present',
|
||||
'array',
|
||||
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed
|
||||
function ($attribute, array $value, $fail) {
|
||||
'title' => 'required|min:3|max:255',
|
||||
'seo_title' => 'required|min:45|max:70',
|
||||
'seo_description' => 'required|min:50|max:160',
|
||||
'type' => ['required', new EnumIsValidRule(AdviceTypeEnum::class)],
|
||||
'picture_alt' => 'required_with:picture|nullable|min:3|max:255',
|
||||
'picture_title' => 'required_with:picture|nullable|min:3|max:255',
|
||||
'sticker_alt' => 'required_with:sticker|nullable|min:3|max:255',
|
||||
'sticker_title' => 'required_with:sticker|nullable|min:3|max:255',
|
||||
'sticker_sm_alt' => 'required_with:sticker_sm|nullable|min:3|max:255',
|
||||
'sticker_sm_title' => 'required_with:sticker_sm|nullable|min:3|max:255',
|
||||
'preparation' => 'required|string|min:15',
|
||||
'advice' => 'nullable|string|min:15',
|
||||
'ingredients' => [
|
||||
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
|
||||
'present', 'array', function ($attribute, array $value, $fail) {
|
||||
if (count($value) < 1 || count($value) > 15) {
|
||||
$fail(\trans('Vous devez associer 1 à 15 lignes d\'ingrédients.'));
|
||||
}
|
||||
}
|
||||
],
|
||||
'ingredients.*' => 'required|array',
|
||||
'ingredients.*.value' => 'nullable|regex:/^\d*\.?\d{0,1}$/|between:0,65535',
|
||||
'ingredients.*.label' => [
|
||||
'ingredients.*' => 'required|array',
|
||||
'ingredients.*.value' => 'nullable|numeric|max:65535',
|
||||
'ingredients.*.label' => [
|
||||
Rule::requiredIf(function () {
|
||||
return $this->type === AdviceTypeEnum::recipes->value();
|
||||
return $this->type === AdviceTypeEnum::recipes()->value;
|
||||
}),
|
||||
//phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed
|
||||
//phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
|
||||
function ($attribute, $value, $fail) {
|
||||
if ($this->type == AdviceTypeEnum::recipes->value()) {
|
||||
if ($this->type == AdviceTypeEnum::recipes()->value) {
|
||||
if (!$value) {
|
||||
$fail(\trans('Le champ description de l\'ingrédient doit être une chaîne de caractères.'));
|
||||
}
|
||||
|
|
@ -119,8 +106,8 @@ class StoreAdviceRequest extends FormRequest
|
|||
},
|
||||
'max:255'
|
||||
],
|
||||
'guests_nb' => [
|
||||
//phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed
|
||||
'guests_nb' => [
|
||||
//phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
|
||||
function ($attribute, $value, $fail) {
|
||||
if (
|
||||
\is_array($this->ingredients) and
|
||||
|
|
@ -129,49 +116,39 @@ class StoreAdviceRequest extends FormRequest
|
|||
) {
|
||||
$fail(\trans('Le nombre de convives est obligatoire'));
|
||||
}
|
||||
},
|
||||
'nullable',
|
||||
'numeric',
|
||||
'min:1',
|
||||
'max:99'
|
||||
}, 'nullable', 'numeric', 'min:1', 'max:99'
|
||||
],
|
||||
'youtube_title' => 'required_with:youtube_video_id|nullable|min:3|max:255',
|
||||
'youtube_video_id' => 'required_with:youtube_title|nullable|min:3|max:50|regex:%([^"&?\/\s]{11})%i',
|
||||
'cooking_time' => 'nullable|numeric|min:0|max:65535',
|
||||
'youtube_title' => 'required_with:youtube_video_id|nullable|min:3|max:255',
|
||||
'youtube_video_id' => 'required_with:youtube_title|nullable|regex:%([^"&?\/\s]{11})%i',
|
||||
'cooking_time' => 'nullable|numeric|min:0|max:65535',
|
||||
'preparation_time' => [
|
||||
Rule::requiredIf(function () {
|
||||
return $this->type === AdviceTypeEnum::recipes->value();
|
||||
return $this->type === AdviceTypeEnum::recipes()->value;
|
||||
}),
|
||||
'numeric',
|
||||
'min:0',
|
||||
'max:65535'
|
||||
'numeric', 'min:0', 'max:65535'
|
||||
],
|
||||
'difficulty' => [
|
||||
'difficulty' => [
|
||||
Rule::requiredIf(function () {
|
||||
return $this->type === AdviceTypeEnum::recipes->value();
|
||||
return $this->type === AdviceTypeEnum::recipes()->value;
|
||||
}),
|
||||
new Enum(AdviceDifficultyEnum::class)
|
||||
new EnumIsValidRule(AdviceDifficultyEnum::class)
|
||||
],
|
||||
'published' => 'required|boolean',
|
||||
'tags' => [
|
||||
'present',
|
||||
'array',
|
||||
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed
|
||||
function ($attribute, array $value, $fail) {
|
||||
'status' => 'required|boolean',
|
||||
'tags' => [
|
||||
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
|
||||
'present', 'array', function ($attribute, array $value, $fail) {
|
||||
if (count($value) > 2) {
|
||||
$fail(\trans('Vous devez associer au maximum 2 tags.'));
|
||||
}
|
||||
}
|
||||
],
|
||||
'tags.*' => 'required|array',
|
||||
'tags.*.id' => 'required|numeric|exists:tags,id|distinct',
|
||||
'tags.*.label' => 'required|string',
|
||||
'products' => [
|
||||
'present',
|
||||
'array',
|
||||
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed
|
||||
function ($attribute, array $value, $fail) {
|
||||
if ($this->type == AdviceTypeEnum::recipes->value()) {
|
||||
'tags.*' => 'required|array',
|
||||
'tags.*.id' => 'required|numeric|exists:tags,id|distinct',
|
||||
'tags.*.label' => 'required|string',
|
||||
'products' => [
|
||||
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
|
||||
'present', 'array', function ($attribute, array $value, $fail) {
|
||||
if ($this->type == AdviceTypeEnum::recipes()->value) {
|
||||
if (count($value) < 1 || count($value) > 3) {
|
||||
$fail(\trans('Vous devez associer 1 à 3 produits.'));
|
||||
}
|
||||
|
|
@ -182,41 +159,37 @@ class StoreAdviceRequest extends FormRequest
|
|||
}
|
||||
}
|
||||
],
|
||||
'products.*' => 'required|array',
|
||||
'products.*.value' => 'required|exists:products,id',
|
||||
'products.*.label' => 'required|string',
|
||||
'associated_tips_list' => [
|
||||
'present',
|
||||
'array',
|
||||
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed
|
||||
function ($attribute, array $value, $fail) {
|
||||
'products.*' => 'required|array',
|
||||
'products.*.value' => 'required|exists:products,id',
|
||||
'products.*.label' => 'required|string',
|
||||
'associated_tips_list' => [
|
||||
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
|
||||
'present', 'array', function ($attribute, array $value, $fail) {
|
||||
if (count($value) > 3) {
|
||||
$fail(\trans('Vous devez associer au maximum 3 astuces.'));
|
||||
}
|
||||
}
|
||||
],
|
||||
'associated_tips_list.*' => 'required|array',
|
||||
'associated_tips_list.*.value' => 'required|exists:advice,id',
|
||||
'associated_tips_list.*.label' => 'required|string',
|
||||
'associated_recipes_list' => [
|
||||
'present',
|
||||
'array',
|
||||
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed
|
||||
function ($attribute, array $value, $fail) {
|
||||
'associated_tips_list.*' => 'required|array',
|
||||
'associated_tips_list.*.value' => 'required|exists:advice,id',
|
||||
'associated_tips_list.*.label' => 'required|string',
|
||||
'associated_recipes_list' => [
|
||||
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
|
||||
'present', 'array', function ($attribute, array $value, $fail) {
|
||||
if (count($value) > 3) {
|
||||
$fail(\trans('Vous devez associer au maximum 3 recettes.'));
|
||||
}
|
||||
}
|
||||
],
|
||||
'associated_recipes_list.*' => 'required|array',
|
||||
'associated_recipes_list.*' => 'required|array',
|
||||
'associated_recipes_list.*.value' => 'required|exists:advice,id',
|
||||
'associated_recipes_list.*.label' => 'required|string',
|
||||
];
|
||||
return \array_merge(
|
||||
$rules,
|
||||
$this->pictureRules('picture', 650, 690, 650, 690, false),
|
||||
$this->pictureRules('sticker', 370, 300, 370, 300, false),
|
||||
$this->pictureRules('sticker_sm', 270, 145, 270, 145, false),
|
||||
$this->pictureRules('picture', true, 650, 690, 650, 690),
|
||||
$this->pictureRules('sticker', true, 370, 300, 370, 300),
|
||||
$this->pictureRules('sticker_sm', true, 270, 145, 270, 145),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -228,30 +201,30 @@ class StoreAdviceRequest extends FormRequest
|
|||
public function attributes(): array
|
||||
{
|
||||
return [
|
||||
'title' => trans('Titre'),
|
||||
'slug' => trans('Slug'),
|
||||
'seo_title' => trans('title') . ' seo',
|
||||
'seo_description' => trans('description') . ' seo',
|
||||
'tags' => trans('tag'),
|
||||
'tags.*' => trans('tag'),
|
||||
'tags.*.id' => trans('id du tag'),
|
||||
'tags.*.label' => trans('label du tag'),
|
||||
'difficulty' => trans('Difficulté'),
|
||||
'picture' => trans('Visuel'),
|
||||
'picture_alt' => trans('Attribut alt du visuel'),
|
||||
'picture_title' => trans('Titre du visuel'),
|
||||
'sticker' => trans('Vignette'),
|
||||
'sticker_alt' => trans('Attribut alt de la vignette'),
|
||||
'sticker_title' => trans('Titre de la vignette'),
|
||||
'sticker_sm' => trans('Petite vignette'),
|
||||
'sticker_sm_alt' => trans('Attribut alt de la petite vignette'),
|
||||
'sticker_sm_title' => trans('Titre de la petite vignette'),
|
||||
'title' => trans('Titre'),
|
||||
'slug' => trans('Slug'),
|
||||
'seo_title' => trans('title') . ' seo',
|
||||
'seo_description' => trans('description') . ' seo',
|
||||
'tags' => trans('tag'),
|
||||
'tags.*' => trans('tag'),
|
||||
'tags.*.id' => trans('id du tag'),
|
||||
'tags.*.label' => trans('label du tag'),
|
||||
'difficulty' => trans('Difficulté'),
|
||||
'picture' => trans('Visuel'),
|
||||
'picture_alt' => trans('Attribut alt du visuel'),
|
||||
'picture_title' => trans('Titre du visuel'),
|
||||
'sticker' => trans('Vignette'),
|
||||
'sticker_alt' => trans('Attribut alt de la vignette'),
|
||||
'sticker_title' => trans('Titre de la vignette'),
|
||||
'sticker_sm' => trans('Petite vignette'),
|
||||
'sticker_sm_alt' => trans('Attribut alt de la petite vignette'),
|
||||
'sticker_sm_title' => trans('Titre de la petite vignette'),
|
||||
'ingredients.*.value' => trans('quantité de l\'ingrédient'),
|
||||
'ingredients.*.label' => trans('description de l\'ingrédient'),
|
||||
'guests_nb' => trans('Nombre de convives'),
|
||||
'youtube_title' => trans('Titre de la vidéo Youtube'),
|
||||
'youtube_video_id' => trans('ID de la vidéo Youtube'),
|
||||
'advice' => trans('Conseil LGP'),
|
||||
'guests_nb' => trans('Nombre de convives'),
|
||||
'youtube_title' => trans('Titre de la vidéo Youtube'),
|
||||
'youtube_video_id' => trans('ID de la vidéo Youtube'),
|
||||
'advice' => trans('Conseil LGP'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,84 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Bo\BrigadeSections;
|
||||
|
||||
use App\Rules\WysiwygLength;
|
||||
use App\Traits\Requests\HasPicture;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class StoreBrigadeSectionsRequest extends FormRequest
|
||||
{
|
||||
use HasPicture;
|
||||
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return auth('backend')->check();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the data for validation.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function prepareForValidation(): void
|
||||
{
|
||||
$this->merge([
|
||||
'published' => $this->boolean('published'),
|
||||
'button_display' => $this->boolean('button_display'),
|
||||
'button_newtab' => $this->boolean('button_newtab'),
|
||||
]);
|
||||
$this->mergePicture('picture');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
$rules = [
|
||||
'title' => 'required|string|min:3|max:500',
|
||||
'content' => [
|
||||
'required',
|
||||
'string',
|
||||
new WysiwygLength(15, 1500)
|
||||
],
|
||||
'picture_alt' => 'required|string|min:3|max:255',
|
||||
'picture_title' => 'required|string|min:3|max:255',
|
||||
'button_display' => 'required|boolean',
|
||||
'button_text' => 'required_if_accepted:button_display|nullable|string|min:3|max:255',
|
||||
'button_url' => 'required_if_accepted:button_display|nullable|url:https|min:3|max:255',
|
||||
'button_newtab' => 'required|boolean',
|
||||
'published' => 'required|boolean',
|
||||
];
|
||||
return \array_merge(
|
||||
$rules,
|
||||
$this->pictureRules('picture', 800, 535, 800, 535, false),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get custom attributes for validator errors.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function attributes(): array
|
||||
{
|
||||
return [
|
||||
'title' => trans('Titre'),
|
||||
'picture' => trans('Image'),
|
||||
'picture_alt' => trans('Attribut alt de l\'image'),
|
||||
'picture_title' => trans('Titre de l\'image'),
|
||||
'content' => trans('Contenu'),
|
||||
'button_text' => trans('Texte du CTA'),
|
||||
'button_url' => trans('URL du CTA'),
|
||||
'published' => trans('Statut'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Bo\BrigadeSections;
|
||||
|
||||
class UpdateBrigadeSectionsRequest extends StoreBrigadeSectionsRequest
|
||||
{
|
||||
}
|
||||
|
|
@ -4,14 +4,14 @@ namespace App\Http\Requests\Bo;
|
|||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class UpdateChangeOrderRequest extends FormRequest
|
||||
class ChangeOrderRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function authorize(): bool
|
||||
public function authorize()
|
||||
{
|
||||
return auth('backend')->check();
|
||||
}
|
||||
|
|
@ -21,10 +21,10 @@ class UpdateChangeOrderRequest extends FormRequest
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function prepareForValidation(): void
|
||||
protected function prepareForValidation()
|
||||
{
|
||||
$this->merge([
|
||||
'direction' => $this->direction === 'up' ? true : false
|
||||
'direction' => $this->action === 'up' ? true : false
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
@ -33,9 +33,10 @@ class UpdateChangeOrderRequest extends FormRequest
|
|||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules(): array
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'action' => 'required|string|in:up,down',
|
||||
'direction' => 'required|boolean',
|
||||
];
|
||||
}
|
||||
|
|
@ -5,7 +5,7 @@ namespace App\Http\Requests\Bo\ExpertiseProducts;
|
|||
use App\Enums\ExpertiseProducts\ExpertiseProductPageEnum;
|
||||
use App\Enums\NutriscoreEnum;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rules\Enum;
|
||||
use Kwaadpepper\Enum\Rules\EnumIsValidRule;
|
||||
|
||||
class StoreExpertiseProductRequest extends FormRequest
|
||||
{
|
||||
|
|
@ -14,7 +14,7 @@ class StoreExpertiseProductRequest extends FormRequest
|
|||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function authorize(): bool
|
||||
public function authorize()
|
||||
{
|
||||
return auth('backend')->check();
|
||||
}
|
||||
|
|
@ -24,12 +24,12 @@ class StoreExpertiseProductRequest extends FormRequest
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function prepareForValidation(): void
|
||||
protected function prepareForValidation()
|
||||
{
|
||||
$this->merge([
|
||||
'is_frenchpoultry' => $this->is_frenchpoultry ? true : false,
|
||||
'is_frenchpoultry' => $this->is_frenchpoultry ? true : false,
|
||||
'is_natureeleveurs' => $this->is_natureeleveurs ? true : false,
|
||||
'points' => $this->points ?? []
|
||||
'points' => $this->points ?? []
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
@ -38,19 +38,19 @@ class StoreExpertiseProductRequest extends FormRequest
|
|||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules(): array
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'page' => ['required', new Enum(ExpertiseProductPageEnum::class)],
|
||||
'label' => 'required|min:3|max:255',
|
||||
'title' => 'required|min:3|max:255',
|
||||
'subtitle' => 'required|min:3|max:255',
|
||||
'points' => 'required|array',
|
||||
'points.*' => 'required|array',
|
||||
'points.*.value' => 'required|min:3|max:255',
|
||||
'is_frenchpoultry' => 'required|boolean',
|
||||
'page' => ['required', new EnumIsValidRule(ExpertiseProductPageEnum::class)],
|
||||
'label' => 'required|min:3|max:255',
|
||||
'title' => 'required|min:3|max:255',
|
||||
'subtitle' => 'required|min:3|max:255',
|
||||
'points' => 'required|array',
|
||||
'points.*' => 'required|array',
|
||||
'points.*.value' => 'required|min:3|max:255',
|
||||
'is_frenchpoultry' => 'required|boolean',
|
||||
'is_natureeleveurs' => 'required|boolean',
|
||||
'nutriscore' => ['required', new Enum(NutriscoreEnum::class)]
|
||||
'nutriscore' => ['required', new EnumIsValidRule(NutriscoreEnum::class)]
|
||||
];
|
||||
}
|
||||
|
||||
|
|
@ -62,16 +62,16 @@ class StoreExpertiseProductRequest extends FormRequest
|
|||
public function attributes(): array
|
||||
{
|
||||
return [
|
||||
'page' => trans('Espèce'),
|
||||
'label' => trans('Libellé du bloc'),
|
||||
'title' => trans('Titre dans le bloc'),
|
||||
'subtitle' => trans('Sous-titre'),
|
||||
'points' => trans('Bloc des points forts'),
|
||||
'points.*' => trans('Point fort'),
|
||||
'points.*.value' => trans('Valeur Point fort'),
|
||||
'is_frenchpoultry' => trans('Label volaille française'),
|
||||
'page' => trans('Espèce'),
|
||||
'label' => trans('Libellé du bloc'),
|
||||
'title' => trans('Titre dans le bloc'),
|
||||
'subtitle' => trans('Sous-titre'),
|
||||
'points' => trans('Bloc des points forts'),
|
||||
'points.*' => trans('Point fort'),
|
||||
'points.*.value' => trans('Valeur Point fort'),
|
||||
'is_frenchpoultry' => trans('Label volaille française'),
|
||||
'is_natureeleveurs' => trans('Label nature d\'éleveur'),
|
||||
'nutriscore' => trans('Label Nutriscore')
|
||||
'nutriscore' => trans('Label Nutriscore')
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace App\Http\Requests\Bo\News;
|
||||
|
||||
use App\Rules\WysiwygLength;
|
||||
use App\Traits\Requests\HasPicture;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Str;
|
||||
|
|
@ -16,7 +15,7 @@ class StoreNewsRequest extends FormRequest
|
|||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function authorize(): bool
|
||||
public function authorize()
|
||||
{
|
||||
return auth('backend')->check();
|
||||
}
|
||||
|
|
@ -25,28 +24,28 @@ class StoreNewsRequest extends FormRequest
|
|||
* Prepare the data for validation.
|
||||
*
|
||||
* @return void
|
||||
* @phpcs:disable Generic.Metrics.CyclomaticComplexity.TooHigh, Squiz.Commenting.FunctionComment.Missing
|
||||
*/
|
||||
protected function prepareForValidation(): void
|
||||
// phpcs:ignore Generic.Metrics.CyclomaticComplexity.TooHigh, Squiz.Commenting.FunctionComment.Missing
|
||||
protected function prepareForValidation()
|
||||
{
|
||||
//phpcs:enable
|
||||
$this->merge([
|
||||
'slug' => Str::slug($this->title),
|
||||
'published' => $this->published ? true : false,
|
||||
'categories' => $this->categories ?? [],
|
||||
'products' => $this->products ?? [],
|
||||
'slug' => Str::slug($this->title),
|
||||
'status' => $this->status ? true : false,
|
||||
'categories' => $this->categories ?? [],
|
||||
'products' => $this->products ?? [],
|
||||
'associated_news_list' => $this->associated_news_list ?? [],
|
||||
// * For sync relations
|
||||
'news_list' => \collect($this->associated_news_list)->map(function ($value) {
|
||||
'news_list' => \collect($this->associated_news_list)->map(function ($value) {
|
||||
return \is_array($value) ? ($value['value'] ?? null) : null;
|
||||
})->filter()->all(),
|
||||
'products_list' => \collect($this->products)->map(function ($value) {
|
||||
'products_list' => \collect($this->products)->map(function ($value) {
|
||||
return \is_array($value) ? ($value['value'] ?? null) : null;
|
||||
})->filter()->all(),
|
||||
'categories_list' => \collect($this->categories)->map(function ($value) {
|
||||
'categories_list' => \collect($this->categories)->map(function ($value) {
|
||||
return \is_array($value) ? ($value['value'] ?? null) : null;
|
||||
})->filter()->all()
|
||||
]);
|
||||
|
||||
$this->mergePicture('picture');
|
||||
$this->mergePicture('picture2');
|
||||
}
|
||||
|
|
@ -56,87 +55,71 @@ class StoreNewsRequest extends FormRequest
|
|||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules(): array
|
||||
public function rules()
|
||||
{
|
||||
$rules = [
|
||||
'title' => 'required|min:3|max:255',
|
||||
'subtitle' => 'required|min:3|max:255',
|
||||
'seo_title' => 'required|min:45|max:70',
|
||||
'seo_description' => 'required|min:50|max:160',
|
||||
'picture_alt' => 'required_with:picture|nullable|min:3|max:255',
|
||||
'picture_title' => 'required_with:picture|nullable|min:3|max:255',
|
||||
'picture2_alt' => 'required_with:picture2|nullable|min:3|max:255',
|
||||
'picture2_title' => 'required_with:picture2|nullable|min:3|max:255',
|
||||
'content' => [
|
||||
'required_with:picture',
|
||||
'nullable',
|
||||
'string',
|
||||
new WysiwygLength(15, 2500)
|
||||
],
|
||||
'content2' => [
|
||||
'required_with:picture2',
|
||||
'nullable',
|
||||
'string',
|
||||
new WysiwygLength(15, 2500)
|
||||
],
|
||||
'event_start' => 'nullable|date_format:Y-m-d',
|
||||
'event_end' => [
|
||||
'title' => 'required|min:3|max:255',
|
||||
'subtitle' => 'required|min:3|max:255',
|
||||
'seo_title' => 'required|min:45|max:70',
|
||||
'seo_description' => 'required|min:50|max:160',
|
||||
'picture_alt' => 'required_with:picture|nullable|min:3|max:255',
|
||||
'picture_title' => 'required_with:picture|nullable|min:3|max:255',
|
||||
'picture2_alt' => 'required_with:picture2|nullable|min:3|max:255',
|
||||
'picture2_title' => 'required_with:picture2|nullable|min:3|max:255',
|
||||
'content' => 'required_with:picture|nullable|string|min:15',
|
||||
'content2' => 'required_with:picture2|nullable|string|min:15',
|
||||
'event_start' => 'nullable|date_format:Y-m-d',
|
||||
'event_end' => [
|
||||
'required_with:event_start',
|
||||
'after_or_equal:event_start',
|
||||
'nullable',
|
||||
'date_format:Y-m-d'
|
||||
],
|
||||
'event_text' => [
|
||||
'event_text' => [
|
||||
'required_with:event_start',
|
||||
'nullable',
|
||||
'min:3',
|
||||
'max:255'
|
||||
],
|
||||
'published' => 'required|boolean',
|
||||
'categories' => [
|
||||
'present',
|
||||
'array',
|
||||
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed
|
||||
function ($attribute, array $value, $fail) {
|
||||
'status' => 'required|boolean',
|
||||
'categories' => [
|
||||
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
|
||||
'present', 'array', function ($attribute, array $value, $fail) {
|
||||
if (count($value) < 1 || count($value) > 2) {
|
||||
$fail(\trans('Vous devez associer une actualité à 1 ou 2 catégories.'));
|
||||
}
|
||||
}
|
||||
],
|
||||
'categories.*' => 'required|array',
|
||||
'categories.*.value' => 'required|exists:news_categories,id',
|
||||
'categories.*.label' => 'required|string',
|
||||
'products' => [
|
||||
'present',
|
||||
'array',
|
||||
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed
|
||||
function ($attribute, array $value, $fail) {
|
||||
'categories.*' => 'required|array',
|
||||
'categories.*.value' => 'required|exists:news_categories,id',
|
||||
'categories.*.label' => 'required|string',
|
||||
'products' => [
|
||||
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
|
||||
'present', 'array', function ($attribute, array $value, $fail) {
|
||||
if (count($value) > 3) {
|
||||
$fail(\trans('Vous devez associer au maximum 3 produits.'));
|
||||
}
|
||||
}
|
||||
],
|
||||
'products.*' => 'required|array',
|
||||
'products.*.value' => 'required|exists:products,id',
|
||||
'products.*.label' => 'required|string',
|
||||
'associated_news_list' => [
|
||||
'present',
|
||||
'array',
|
||||
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed
|
||||
function ($attribute, array $value, $fail) {
|
||||
'products.*' => 'required|array',
|
||||
'products.*.value' => 'required|exists:products,id',
|
||||
'products.*.label' => 'required|string',
|
||||
'associated_news_list' => [
|
||||
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
|
||||
'present', 'array', function ($attribute, array $value, $fail) {
|
||||
if (count($value) > 3) {
|
||||
$fail(\trans('Vous devez associer au maximum 3 actualités.'));
|
||||
}
|
||||
}
|
||||
],
|
||||
'associated_news_list.*' => 'required|array',
|
||||
'associated_news_list.*' => 'required|array',
|
||||
'associated_news_list.*.value' => 'required|exists:news,id',
|
||||
'associated_news_list.*.label' => 'required|string',
|
||||
];
|
||||
return \array_merge(
|
||||
$rules,
|
||||
$this->pictureRules('picture', 590, 645, 590, 645, false),
|
||||
$this->pictureRules('picture2', 590, 645, 590, 645, true, requiredWith: 'content2')
|
||||
$this->pictureRules('picture', true, 920, 1025, 920, 1025),
|
||||
$this->pictureRules('picture2', false, 920, 1025, 920, 1025)
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -148,23 +131,23 @@ class StoreNewsRequest extends FormRequest
|
|||
public function attributes(): array
|
||||
{
|
||||
return [
|
||||
'title' => trans('Titre'),
|
||||
'slug' => trans('Slug'),
|
||||
'seo_title' => trans('title') . ' seo',
|
||||
'title' => trans('Titre'),
|
||||
'slug' => trans('Slug'),
|
||||
'seo_title' => trans('title') . ' seo',
|
||||
'seo_description' => trans('description') . ' seo',
|
||||
'subtitle' => trans('Sous-titre'),
|
||||
'picture' => trans('Image'),
|
||||
'picture_alt' => trans('Attribut alt de l\'image'),
|
||||
'picture_title' => trans('Titre de l\'image'),
|
||||
'picture2' => trans('Image 2'),
|
||||
'picture2_alt' => trans('Attribut alt de l\'image 2'),
|
||||
'picture2_title' => trans('Titre de l\'image 2'),
|
||||
'content' => trans('Contenu'),
|
||||
'content2' => trans('Contenu 2'),
|
||||
'event_start' => trans('Date de début de l\'évènement'),
|
||||
'event_end' => trans('Date de fin de l\'évènement'),
|
||||
'event_text' => trans('Description de l\'évènement'),
|
||||
'published' => trans('Status'),
|
||||
'subtitle' => trans('Sous-titre'),
|
||||
'picture' => trans('Image'),
|
||||
'picture_alt' => trans('Attribut alt de l\'image'),
|
||||
'picture_title' => trans('Titre de l\'image'),
|
||||
'picture2' => trans('Image 2'),
|
||||
'picture2_alt' => trans('Attribut alt de l\'image 2'),
|
||||
'picture2_title' => trans('Titre de l\'image 2'),
|
||||
'content' => trans('Contenu'),
|
||||
'content2' => trans('Contenu 2'),
|
||||
'event_start' => trans('Date de début de l\'évènement'),
|
||||
'event_end' => trans('Date de fin de l\'évènement'),
|
||||
'event_text' => trans('Description de l\'évènement'),
|
||||
'status' => trans('Status'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ class UpdateNewsCategoryRequest extends FormRequest
|
|||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function authorize(): bool
|
||||
public function authorize()
|
||||
{
|
||||
return auth('backend')->check();
|
||||
}
|
||||
|
|
@ -22,7 +22,7 @@ class UpdateNewsCategoryRequest extends FormRequest
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function prepareForValidation(): void
|
||||
protected function prepareForValidation()
|
||||
{
|
||||
$this->merge([
|
||||
'slug' => Str::slug(strip_tags($this->label))
|
||||
|
|
@ -34,7 +34,7 @@ class UpdateNewsCategoryRequest extends FormRequest
|
|||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules(): array
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'label' => 'required|min:3|max:30',
|
||||
|
|
@ -50,7 +50,7 @@ class UpdateNewsCategoryRequest extends FormRequest
|
|||
{
|
||||
return [
|
||||
'label' => trans('label'),
|
||||
'slug' => trans('slug'),
|
||||
'slug' => trans('slug'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,11 +4,10 @@ namespace App\Http\Requests\Bo\Products;
|
|||
|
||||
use App\Enums\NutriscoreEnum;
|
||||
use App\Enums\Products\ProductSpeciesEnum;
|
||||
use App\Rules\WysiwygLength;
|
||||
use App\Traits\Requests\HasPicture;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\Rules\Enum;
|
||||
use Kwaadpepper\Enum\Rules\EnumIsValidRule;
|
||||
|
||||
class StoreProductRequest extends FormRequest
|
||||
{
|
||||
|
|
@ -19,7 +18,7 @@ class StoreProductRequest extends FormRequest
|
|||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function authorize(): bool
|
||||
public function authorize()
|
||||
{
|
||||
return auth('backend')->check();
|
||||
}
|
||||
|
|
@ -29,26 +28,16 @@ class StoreProductRequest extends FormRequest
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function prepareForValidation(): void
|
||||
protected function prepareForValidation()
|
||||
{
|
||||
$this->merge([
|
||||
'slug' => Str::slug(strip_tags($this->name)),
|
||||
'slug' => Str::slug(strip_tags($this->name)),
|
||||
'is_frenchpoultry' => $this->is_frenchpoultry ? true : false,
|
||||
'is_vip' => $this->is_vip ? true : false,
|
||||
'is_egalim' => $this->is_egalim ? true : false,
|
||||
'published' => $this->published ? true : false,
|
||||
'tags' => $this->input('tags', []),
|
||||
// * For sync relations
|
||||
'tags_list' => \collect($this->input('tags'))->map(function ($value) {
|
||||
return \is_array($value) ? ($value['value'] ?? null) : null;
|
||||
})->filter()->all(),
|
||||
'is_vip' => $this->is_vip ? true : false,
|
||||
'is_egalim' => $this->is_egalim ? true : false,
|
||||
'status' => $this->status ? true : false
|
||||
]);
|
||||
$this->mergePicture('sticker_sm');
|
||||
($this->slider_pictures)
|
||||
? $this->mergePictures('slider_pictures')
|
||||
: $this->merge([
|
||||
'slider_pictures' => [],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -56,80 +45,61 @@ class StoreProductRequest extends FormRequest
|
|||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules(): array
|
||||
public function rules()
|
||||
{
|
||||
$rules = [
|
||||
'label' => 'required|min:3|max:255',
|
||||
'seo_title' => 'required|min:45|max:70',
|
||||
'seo_description' => 'required|min:50|max:160',
|
||||
'subrange_id' => 'required',
|
||||
'species' => ['required', new Enum(ProductSpeciesEnum::class)],
|
||||
'nutriscore' => ['required', new Enum(NutriscoreEnum::class)],
|
||||
'sticker_sm_alt' => 'required|min:3|max:255',
|
||||
'sticker_sm_title' => 'required|min:3|max:255',
|
||||
'ingredients' => [
|
||||
'required',
|
||||
'string',
|
||||
new WysiwygLength(15, 2500)
|
||||
],
|
||||
'advantage' => [
|
||||
'required',
|
||||
'string',
|
||||
new WysiwygLength(15, 2500)
|
||||
],
|
||||
'preparation' => [
|
||||
'required',
|
||||
'string',
|
||||
new WysiwygLength(15, 2500)
|
||||
],
|
||||
'packaging' => [
|
||||
'present',
|
||||
'array',
|
||||
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed
|
||||
function ($attribute, array $value, $fail) {
|
||||
'label' => 'required|min:3|max:255',
|
||||
'seo_title' => 'required|min:45|max:70',
|
||||
'seo_description' => 'required|min:50|max:160',
|
||||
'subrange_id' => 'required',
|
||||
'species' => ['required', new EnumIsValidRule(ProductSpeciesEnum::class)],
|
||||
'nutriscore' => ['required', new EnumIsValidRule(NutriscoreEnum::class)],
|
||||
'sticker_sm_alt' => 'required|min:3|max:255',
|
||||
'sticker_sm_title' => 'required|min:3|max:255',
|
||||
'ingredients' => 'required|string|min:15',
|
||||
'advantage' => 'required|string|min:15',
|
||||
'preparation' => 'required|string|min:15',
|
||||
'packaging' => [
|
||||
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
|
||||
'present', 'array', function ($attribute, array $value, $fail) {
|
||||
if (1 > count($value) || count($value) > 6) {
|
||||
$fail(\trans('Vous devez remplir au moins 1 ligne et au plus 6 lignes de conditionnement.'));
|
||||
}
|
||||
}
|
||||
],
|
||||
'packaging.*' => 'required|array',
|
||||
'packaging.*.value' => 'required|string|min:2|max:255',
|
||||
'caliber' => [
|
||||
'present',
|
||||
'array',
|
||||
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed
|
||||
function ($attribute, array $value, $fail) {
|
||||
'packaging.*' => 'required|array',
|
||||
'packaging.*.value' => 'required|string|min:2|max:255',
|
||||
'caliber' => [
|
||||
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
|
||||
'present', 'array', function ($attribute, array $value, $fail) {
|
||||
if (1 > count($value) || count($value) > 6) {
|
||||
$fail(\trans('Vous devez remplir au moins 1 ligne et au plus 6 lignes de calibre.'));
|
||||
}
|
||||
}
|
||||
],
|
||||
'caliber.*' => 'required|array',
|
||||
'caliber.*.value' => 'required|string|min:1|max:255',
|
||||
'is_frenchpoultry' => 'required|boolean',
|
||||
'is_vip' => 'required|boolean',
|
||||
'is_egalim' => 'required|boolean',
|
||||
'published' => 'required|boolean',
|
||||
// * TAGS
|
||||
'tags' => [
|
||||
'present',
|
||||
'array',
|
||||
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed
|
||||
function ($attribute, array $value, $fail) {
|
||||
if (count($value) > 2) {
|
||||
$fail(\trans('Vous devez associer au maximum 2 tags.'));
|
||||
'caliber.*' => 'required|array',
|
||||
'caliber.*.value' => 'required|string|min:1|max:255',
|
||||
'nutritionnal_values' => 'required|array',
|
||||
'nutritionnal_values' => [
|
||||
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
|
||||
'present', 'array', function ($attribute, array $value, $fail) {
|
||||
if (count($value) != 9) {
|
||||
$fail(\trans('Vous devez remplir seulement 9 lignes de valeurs nutritionnelles.'));
|
||||
}
|
||||
}
|
||||
],
|
||||
'tags.*' => 'required|array',
|
||||
'tags.*.id' => 'required|numeric|exists:tags,id|distinct',
|
||||
'tags.*.label' => 'required|string',
|
||||
|
||||
'nutritionnal_values.*' => 'nullable|array',
|
||||
'nutritionnal_values.*.label' => 'nullable|string|min:3|max:255',
|
||||
'nutritionnal_values.*.value' => 'nullable|numeric|min:0',
|
||||
'is_frenchpoultry' => 'required|boolean',
|
||||
'is_vip' => 'required|boolean',
|
||||
'is_egalim' => 'required|boolean',
|
||||
'status' => 'required|boolean'
|
||||
];
|
||||
return \array_merge(
|
||||
$rules,
|
||||
$this->pictureRules('sticker_sm', 206, 159, 206, 159, false),
|
||||
$this->picturesRules('slider_pictures', 396, 286, 396, 286, 1, 5, true),
|
||||
$this->pictureRules('sticker_sm', true, 206, 159, 206, 159),
|
||||
$this->picturesRules('slider_pictures', true, 396, 286, 396, 286, 1, 5),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -141,30 +111,29 @@ class StoreProductRequest extends FormRequest
|
|||
public function attributes(): array
|
||||
{
|
||||
return [
|
||||
'label' => trans('title'),
|
||||
'slug' => trans('slug'),
|
||||
'seo_title' => trans('title') . ' seo',
|
||||
'seo_description' => trans('description') . ' seo',
|
||||
'subrange_id' => trans('sous-gamme'),
|
||||
'species' => trans('Espèce du produit'),
|
||||
'nutriscore' => trans('Label Nutriscore'),
|
||||
'sticker_sm' => trans('miniature'),
|
||||
'sticker_sm_alt' => trans('attribut alt de la miniature'),
|
||||
'sticker_sm_title' => trans('titre de la miniature'),
|
||||
'slider_pictures' => trans('images du slider'),
|
||||
'label' => trans('title'),
|
||||
'slug' => trans('slug'),
|
||||
'seo_title' => trans('title') . ' seo',
|
||||
'seo_description' => trans('description') . ' seo',
|
||||
'subrange_id' => trans('sous-gamme'),
|
||||
'species' => trans('Espèce du produit'),
|
||||
'nutriscore' => trans('Label Nutriscore'),
|
||||
'sticker_sm' => trans('miniature'),
|
||||
'sticker_sm_alt' => trans('attribut alt de la miniature'),
|
||||
'sticker_sm_title' => trans('titre de la miniature'),
|
||||
'slider_pictures' => trans('images du slider'),
|
||||
'slider_pictures.*' => trans('image du slider'),
|
||||
'packaging' => trans('conditionnement'),
|
||||
'packaging' => trans('conditionnement'),
|
||||
'packaging.*.value' => trans('valeur du conditionnement'),
|
||||
'caliber' => trans('calibre'),
|
||||
'caliber.*.value' => trans('valeur du calibre'),
|
||||
'is_frenchpoultry' => trans('Label volaille française'),
|
||||
'is_vip' => trans('Produit VIP'),
|
||||
'is_egalim' => trans('Produit Égalim'),
|
||||
'published' => trans('publish'),
|
||||
'tags' => trans('tag'),
|
||||
'tags.*' => trans('tag'),
|
||||
'tags.*.id' => trans('id du tag'),
|
||||
'tags.*.label' => trans('label du tag'),
|
||||
'caliber' => trans('calibre'),
|
||||
'caliber.*.value' => trans('valeur du calibre'),
|
||||
'nutritionnal_values' => trans('valeurs nutritionnelles'),
|
||||
'nutritionnal_values.*.label' => trans('libellé de la valeur nutritionnelle'),
|
||||
'nutritionnal_values.*.value' => trans('valeur de la valeur nutritionnelle'),
|
||||
'is_frenchpoultry' => trans('Label volaille française'),
|
||||
'is_vip' => trans('Produit VIP'),
|
||||
'is_egalim' => trans('Produit Égalim'),
|
||||
'status' => trans('publish')
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ class UpdateRangeRequest extends FormRequest
|
|||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function authorize(): bool
|
||||
public function authorize()
|
||||
{
|
||||
return auth('backend')->check();
|
||||
}
|
||||
|
|
@ -25,7 +25,7 @@ class UpdateRangeRequest extends FormRequest
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function prepareForValidation(): void
|
||||
protected function prepareForValidation()
|
||||
{
|
||||
$this->merge([
|
||||
'slug' => Str::slug(strip_tags($this->label))
|
||||
|
|
@ -39,22 +39,22 @@ class UpdateRangeRequest extends FormRequest
|
|||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules(): array
|
||||
public function rules()
|
||||
{
|
||||
$rules = [
|
||||
'label' => 'required|min:3|max:255',
|
||||
'seo_title' => 'required|min:45|max:70',
|
||||
'seo_description' => 'required|min:50|max:160',
|
||||
'color' => 'required|color_rgba',
|
||||
'picture_alt' => 'required|min:3|max:255',
|
||||
'picture_title' => 'required|min:3|max:255',
|
||||
'picture_banner_alt' => 'required|min:3|max:255',
|
||||
'label' => 'required|min:3|max:255',
|
||||
'seo_title' => 'required|min:45|max:70',
|
||||
'seo_description' => 'required|min:50|max:160',
|
||||
'color' => 'required|color_rgba',
|
||||
'picture_alt' => 'required|min:3|max:255',
|
||||
'picture_title' => 'required|min:3|max:255',
|
||||
'picture_banner_alt' => 'required|min:3|max:255',
|
||||
'picture_banner_title' => 'required|min:3|max:255',
|
||||
];
|
||||
return \array_merge(
|
||||
$rules,
|
||||
$this->pictureRules('picture', 290, 232, 290, 232, true),
|
||||
$this->pictureRules('picture_banner', 1440, 300, 1440, 300, true),
|
||||
$this->pictureRules('picture', true, 290, 232, 290, 232),
|
||||
$this->pictureRules('picture_banner', true, 1440, 300, 1440, 300),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -66,16 +66,16 @@ class UpdateRangeRequest extends FormRequest
|
|||
public function attributes(): array
|
||||
{
|
||||
return [
|
||||
'label' => trans('label'),
|
||||
'slug' => trans('slug'),
|
||||
'seo_title' => trans('title') . ' seo',
|
||||
'seo_description' => trans('description') . ' seo',
|
||||
'color' => trans('couleur'),
|
||||
'picture' => trans('Illustration'),
|
||||
'picture_alt' => trans('attribut alt de l\'image'),
|
||||
'picture_title' => trans('titre de l\'image'),
|
||||
'picture_banner' => trans('bannière'),
|
||||
'picture_banner_alt' => trans('attribut alt de la bannière'),
|
||||
'label' => trans('label'),
|
||||
'slug' => trans('slug'),
|
||||
'seo_title' => trans('title') . ' seo',
|
||||
'seo_description' => trans('description') . ' seo',
|
||||
'color' => trans('couleur'),
|
||||
'picture' => trans('Illustration'),
|
||||
'picture_alt' => trans('attribut alt de l\'image'),
|
||||
'picture_title' => trans('titre de l\'image'),
|
||||
'picture_banner' => trans('bannière'),
|
||||
'picture_banner_alt' => trans('attribut alt de la bannière'),
|
||||
'picture_banner_title' => trans('titre de la bannière'),
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace App\Http\Requests\Bo\Slides;
|
||||
|
||||
use App\Rules\WysiwygLength;
|
||||
use App\Traits\Requests\HasPicture;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
|
|
@ -15,7 +14,7 @@ class StoreSlideRequest extends FormRequest
|
|||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function authorize(): bool
|
||||
public function authorize()
|
||||
{
|
||||
return auth('backend')->check();
|
||||
}
|
||||
|
|
@ -25,12 +24,11 @@ class StoreSlideRequest extends FormRequest
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function prepareForValidation(): void
|
||||
protected function prepareForValidation()
|
||||
{
|
||||
$this->merge([
|
||||
'button_display' => $this->boolean('button_display'),
|
||||
'button_targetblank' => $this->boolean('button_targetblank'),
|
||||
'published' => $this->boolean('published'),
|
||||
'button_display' => $this->button_display ? true : false,
|
||||
'button_targetblank' => $this->button_targetblank ? true : false,
|
||||
]);
|
||||
$this->mergePicture('picture');
|
||||
$this->mergePicture('picture_thumbnail');
|
||||
|
|
@ -41,29 +39,24 @@ class StoreSlideRequest extends FormRequest
|
|||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules(): array
|
||||
public function rules()
|
||||
{
|
||||
$rules = [
|
||||
'title' => 'required|min:3|max:255',
|
||||
'content' => [
|
||||
'required',
|
||||
'string',
|
||||
new WysiwygLength(15, 2500)
|
||||
],
|
||||
'button_display' => 'required|boolean',
|
||||
'button_text' => 'nullable|min:3|max:45',
|
||||
'button_url' => 'nullable|min:3|max:255|url',
|
||||
'button_targetblank' => 'required|boolean',
|
||||
'picture_alt' => 'required|min:3|max:255',
|
||||
'picture_title' => 'required|min:3|max:255',
|
||||
'picture_thumbnail_alt' => 'required|min:3|max:255',
|
||||
'picture_thumbnail_title' => 'required|min:3|max:255',
|
||||
'published' => 'required|boolean',
|
||||
'title' => 'required|min:3|max:255',
|
||||
'content' => 'required|string|min:15',
|
||||
'button_display' => 'required|boolean',
|
||||
'button_text' => 'nullable|min:3|max:45',
|
||||
'button_url' => 'nullable|min:3|max:255|url',
|
||||
'button_targetblank' => 'required|boolean',
|
||||
'picture_alt' => 'required|min:3|max:255',
|
||||
'picture_title' => 'required|min:3|max:255',
|
||||
'picture_thumbnail_alt' => 'required|min:3|max:255',
|
||||
'picture_thumbnail_title' => 'required|min:3|max:255'
|
||||
];
|
||||
return \array_merge(
|
||||
$rules,
|
||||
$this->pictureRules('picture', 950, 700, 950, 700, true),
|
||||
$this->pictureRules('picture_thumbnail', 167, 70, 167, 70, true)
|
||||
$this->pictureRules('picture', true, 950, 700, 950, 700),
|
||||
$this->pictureRules('picture_thumbnail', true, 167, 70, 167, 70)
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -75,17 +68,17 @@ class StoreSlideRequest extends FormRequest
|
|||
public function attributes(): array
|
||||
{
|
||||
return [
|
||||
'title' => trans('title'),
|
||||
'content' => trans('contenu de la slide'),
|
||||
'button_display' => trans('afficher le bouton'),
|
||||
'button_text' => trans('texte du bouton'),
|
||||
'button_url' => trans('url du bouton'),
|
||||
'button_targetblank' => trans('ouvrir dans un nouvel onglet'),
|
||||
'picture' => trans('Illustration'),
|
||||
'picture_alt' => trans('attribut alt de l\'image'),
|
||||
'picture_title' => trans('titre de l\'image'),
|
||||
'picture_thumbnail' => trans('vignette'),
|
||||
'picture_thumbnail_alt' => trans('attribut alt de la vignette'),
|
||||
'title' => trans('title'),
|
||||
'content' => trans('contenu de la slide'),
|
||||
'button_display' => trans('afficher le bouton'),
|
||||
'button_text' => trans('texte du bouton'),
|
||||
'button_url' => trans('url du bouton'),
|
||||
'button_targetblank' => trans('ouvrir dans un nouvel onglet'),
|
||||
'picture' => trans('Illustration'),
|
||||
'picture_alt' => trans('attribut alt de l\'image'),
|
||||
'picture_title' => trans('titre de l\'image'),
|
||||
'picture_thumbnail' => trans('vignette'),
|
||||
'picture_thumbnail_alt' => trans('attribut alt de la vignette'),
|
||||
'picture_thumbnail_title' => trans('titre de la vignette')
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,46 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Bo\StaticPages;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
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 auth('backend')->check();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the data for validation.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function prepareForValidation(): void
|
||||
{
|
||||
$this->merge([
|
||||
'content' => Str::of($this->post('content'))->value()
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -2,10 +2,8 @@
|
|||
|
||||
namespace App\Http\Requests\Bo\Tags;
|
||||
|
||||
use App\Enums\TagTypeEnum;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class StoreTagRequest extends FormRequest
|
||||
{
|
||||
|
|
@ -14,7 +12,7 @@ class StoreTagRequest extends FormRequest
|
|||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function authorize(): bool
|
||||
public function authorize()
|
||||
{
|
||||
return auth('backend')->check();
|
||||
}
|
||||
|
|
@ -24,7 +22,7 @@ class StoreTagRequest extends FormRequest
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
public function prepareForValidation(): void
|
||||
public function prepareForValidation()
|
||||
{
|
||||
$this->merge([
|
||||
'slug' => Str::slug($this->label),
|
||||
|
|
@ -36,14 +34,10 @@ class StoreTagRequest extends FormRequest
|
|||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules(): array
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'label' => 'required|min:2|max:30',
|
||||
'type' => [
|
||||
'required',
|
||||
Rule::enum(TagTypeEnum::class),
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
|
|
@ -56,8 +50,7 @@ class StoreTagRequest extends FormRequest
|
|||
{
|
||||
return [
|
||||
'label' => trans('libellé'),
|
||||
'slug' => trans('slug'),
|
||||
'type' => trans('type'),
|
||||
'slug' => trans('slug'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,68 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Bo;
|
||||
|
||||
use App\Interfaces\OrderableInterface;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class UpdateOrderRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Attribute model needed.
|
||||
*
|
||||
* @var Model $orderable
|
||||
*/
|
||||
private Model $orderable;
|
||||
|
||||
/**
|
||||
* 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->orderable = collect($this->route()->parameters())
|
||||
->first(fn($param) => $param instanceof Model);
|
||||
|
||||
$groupField = $this->orderable->getOrderGroupField();
|
||||
|
||||
if ($groupField) {
|
||||
$this->orderable::query()->where($groupField, $this->orderable->{$groupField});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'priority_order' => [
|
||||
'required',
|
||||
'integer',
|
||||
'min:1',
|
||||
sprintf('max:%s', $this->orderable->max('priority_order')),
|
||||
function ($value, $fail) {
|
||||
// phpcs:ignore Generic.Files.LineLength.TooLong
|
||||
if ($this->orderable instanceof OrderableInterface && intval($value) === $this->orderable->getPriorityOrder()) {
|
||||
$fail(trans('validation.custom.same_priority'));
|
||||
}
|
||||
},
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@ use App\Enums\Contact\ContactActivityEnum;
|
|||
use App\Enums\Contact\ContactTimeEnum;
|
||||
use App\Lib\Helpers\ToolboxHelper;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rules\Enum;
|
||||
use Kwaadpepper\Enum\Rules\EnumIsValidRule;
|
||||
|
||||
class ContactRequest extends FormRequest
|
||||
{
|
||||
|
|
@ -15,45 +15,32 @@ class ContactRequest extends FormRequest
|
|||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function authorize(): bool
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the data for validation.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function prepareForValidation(): void
|
||||
{
|
||||
$this->merge([
|
||||
'opt_in' => $this->boolean('opt_in'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules(): array
|
||||
public function rules()
|
||||
{
|
||||
ToolboxHelper::validateRecaptcha($this, \config('services.google.recaptcha.version'));
|
||||
|
||||
return [
|
||||
'firstname' => 'nullable|min:2|max:255',
|
||||
'lastname' => 'required|min:2|max:255',
|
||||
'email' => 'required|email:rfc,dns,spoof|max:255',
|
||||
'phone' => 'required|max:255|phone:' . implode(',', $this->isoCodes()),
|
||||
'activity' => ['required', new Enum(ContactActivityEnum::class)],
|
||||
'society' => 'nullable|string|max:255',
|
||||
'postcode' => 'required|postal_code:' . implode(',', $this->isoCodes()),
|
||||
'city' => 'nullable|string|max:255',
|
||||
'message' => 'required|string|min:20|max:255',
|
||||
'callTime' => ['required', new Enum(ContactTimeEnum::class)],
|
||||
'brigade' => 'nullable|boolean',
|
||||
'opt_in' => 'required|boolean',
|
||||
'lastname' => 'required|min:2|max:255',
|
||||
'email' => 'required|email:rfc,dns,spoof|max:255',
|
||||
'phone' => 'required|max:255|phone:' . implode(',', $this->isoCodes()),
|
||||
'activity' => ['required', new EnumIsValidRule(ContactActivityEnum::class)],
|
||||
'society' => 'nullable|string|max:255',
|
||||
'postcode' => 'nullable|postal_code:' . implode(',', $this->isoCodes()),
|
||||
'city' => 'nullable|string|max:255',
|
||||
'message' => 'required|string|min:20|max:255',
|
||||
'callTime' => ['required', new EnumIsValidRule(ContactTimeEnum::class)],
|
||||
'rgpd' => 'accepted'
|
||||
];
|
||||
}
|
||||
|
||||
|
|
@ -62,17 +49,17 @@ class ContactRequest extends FormRequest
|
|||
*
|
||||
* @return array
|
||||
*/
|
||||
public function messages(): array
|
||||
public function messages()
|
||||
{
|
||||
return [
|
||||
'phone.phone' => trans(
|
||||
'Le champ :attribute est invalide, il accepte les numéros des pays suivants :countries.',
|
||||
['countries' => implode(', ', array_keys($this->isoCodes()))]
|
||||
),
|
||||
'postcode.postal_code' => trans(
|
||||
'Le champ :attribute est invalide, il accepte les codes postaux des pays suivants :countries.',
|
||||
['countries' => implode(', ', array_keys($this->isoCodes()))]
|
||||
),
|
||||
// phpcs:ignore Generic.Files.LineLength.TooLong
|
||||
'phone.phone' => trans('Le champ :attribute est invalide, il accepte les numéros des pays suivants :countries.', [
|
||||
'countries' => implode(', ', array_keys($this->isoCodes()))
|
||||
]),
|
||||
// phpcs:ignore Generic.Files.LineLength.TooLong
|
||||
'postcode.postal_code' => trans('Le champ :attribute est invalide, il accepte les codes postaux des pays suivants :countries.', [
|
||||
'countries' => implode(', ', array_keys($this->isoCodes()))
|
||||
]),
|
||||
];
|
||||
}
|
||||
|
||||
|
|
@ -85,17 +72,16 @@ class ContactRequest extends FormRequest
|
|||
{
|
||||
return [
|
||||
'firstname' => trans('prénom'),
|
||||
'lastname' => trans('nom'),
|
||||
'email' => trans('email'),
|
||||
'phone' => trans('téléphone'),
|
||||
'activity' => trans('activité'),
|
||||
'society' => trans('société'),
|
||||
'postcode' => trans('code postal'),
|
||||
'city' => trans('ville'),
|
||||
'message' => trans('message'),
|
||||
'callTime' => trans('préférence de rappel'),
|
||||
'brigade' => trans('La Brigade'),
|
||||
'opt_in' => trans('newsletter'),
|
||||
'lastname' => trans('nom'),
|
||||
'email' => trans('email'),
|
||||
'phone' => trans('téléphone'),
|
||||
'activity' => trans('activité'),
|
||||
'society' => trans('société'),
|
||||
'postcode' => trans('code postal'),
|
||||
'city' => trans('ville'),
|
||||
'message' => trans('message'),
|
||||
'callTime' => trans('préférence de rappel'),
|
||||
'rgpd' => trans('condition d\'utilisation'),
|
||||
];
|
||||
}
|
||||
|
||||
|
|
@ -107,20 +93,20 @@ class ContactRequest extends FormRequest
|
|||
private function isoCodes(): array
|
||||
{
|
||||
return [
|
||||
'france' => 'FR',
|
||||
'belgium' => 'BE',
|
||||
'luxembourg' => 'LU',
|
||||
'guadeloupe' => 'GP',
|
||||
'martinique' => 'MQ',
|
||||
'frenchGuiana' => 'GF',
|
||||
'reunion' => 'RE',
|
||||
'france' => 'FR',
|
||||
'belgium' => 'BE',
|
||||
'luxembourg' => 'LU',
|
||||
'guadeloupe' => 'GP',
|
||||
'martinique' => 'MQ',
|
||||
'frenchGuiana' => 'GF',
|
||||
'reunion' => 'RE',
|
||||
'saintPierreAndMiquelon' => 'PM',
|
||||
'mayotte' => 'YT',
|
||||
'saintBarthelemy' => 'BL',
|
||||
'saintMartinFrenchPart' => 'MF',
|
||||
'wallisAndFutuna' => 'WF',
|
||||
'frenchPolynesia' => 'PF',
|
||||
'newCaledonia' => 'NC',
|
||||
'mayotte' => 'YT',
|
||||
'saintBarthelemy' => 'BL',
|
||||
'saintMartinFrenchPart' => 'MF',
|
||||
'wallisAndFutuna' => 'WF',
|
||||
'frenchPolynesia' => 'PF',
|
||||
'newCaledonia' => 'NC',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,30 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Fo\Newsletter;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class SingleOptinRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'email' => 'required|email:rfc,dns,spoof',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Fo\Newsletter;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class UnsubscribeNewsletterRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'hashcode' => 'required|uuid'
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -11,7 +11,7 @@ class AjaxAddProductBasket extends FormRequest
|
|||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function authorize(): bool
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
|
@ -21,12 +21,12 @@ class AjaxAddProductBasket extends FormRequest
|
|||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules(): array
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'packaging' => 'array',
|
||||
'packaging' => 'required|array|min:1',
|
||||
'packaging.*' => [
|
||||
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed
|
||||
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
|
||||
function ($attribute, $value, $fail) {
|
||||
$containsAttribute = (bool)collect($this->publishedProduct->packaging)
|
||||
->filter(function (array $package) use ($value) {
|
||||
|
|
@ -37,9 +37,9 @@ class AjaxAddProductBasket extends FormRequest
|
|||
}
|
||||
}
|
||||
],
|
||||
'caliber' => 'array',
|
||||
'caliber.*' => [
|
||||
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed
|
||||
'caliber' => 'required|array|min:1',
|
||||
'caliber.*' => [
|
||||
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
|
||||
function ($attribute, $value, $fail) {
|
||||
$containsAttribute = (bool)collect($this->publishedProduct->caliber)
|
||||
->filter(function (array $calibe) use ($value) {
|
||||
|
|
@ -56,13 +56,13 @@ class AjaxAddProductBasket extends FormRequest
|
|||
/**
|
||||
* Get custom attributes for validator errors.
|
||||
*
|
||||
* @return array<string,string>
|
||||
* @return array
|
||||
*/
|
||||
public function attributes(): array
|
||||
{
|
||||
return [
|
||||
'packaging' => trans('conditionnement'),
|
||||
'caliber' => trans('calibre'),
|
||||
'caliber' => trans('calibre'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ class AjaxFilterProductsRequest extends FormRequest
|
|||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function authorize(): bool
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
|
@ -24,12 +24,11 @@ class AjaxFilterProductsRequest extends FormRequest
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
public function prepareForValidation(): void
|
||||
public function prepareForValidation()
|
||||
{
|
||||
$this->merge([
|
||||
'vip' => $this->vip ? true : false,
|
||||
'subranges' => isset($this->subranges) ?
|
||||
explode(',', $this->subranges) : (\is_array($this->subranges) ? $this->subranges : [])
|
||||
'vip' => $this->vip ? true : false,
|
||||
'subranges' => \is_array($this->subranges) ? $this->subranges : []
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
@ -38,7 +37,7 @@ class AjaxFilterProductsRequest extends FormRequest
|
|||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules(): array
|
||||
public function rules()
|
||||
{
|
||||
$rules = [];
|
||||
if ($this->ajax()) {
|
||||
|
|
@ -47,7 +46,7 @@ class AjaxFilterProductsRequest extends FormRequest
|
|||
$rules['subranges'] = 'present|array';
|
||||
$rules['subranges.*'] = [
|
||||
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
|
||||
'exists:subranges,id', function (string $attribute, $value, callable $fail) {
|
||||
'exists:subranges,id', function ($attribute, $value, $fail) {
|
||||
if (empty($this->range) or !\is_object($this->range) or \get_class($this->range) !== Range::class) {
|
||||
$fail(trans('La gamme est obligatoire', ['attribute' => $attribute]));
|
||||
return;
|
||||
|
|
@ -59,7 +58,7 @@ class AjaxFilterProductsRequest extends FormRequest
|
|||
$hasSubrange = Range::query()->whereHas('subranges', function (Builder $q) use ($subrange) {
|
||||
$q->where('id', $subrange->id);
|
||||
})->where('id', $this->range->id)->exists();
|
||||
if (!$hasSubrange) {
|
||||
if (empty($value) or !$hasSubrange) {
|
||||
$fail(trans(':attribute doit appartenir à la bonne gamme', ['attribute' => $attribute]));
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
namespace App\Http\Resources\Fo\Products;
|
||||
|
||||
use App\Models\Product;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class ProductCommercialSheetResource extends JsonResource
|
||||
|
|
@ -13,23 +12,24 @@ class ProductCommercialSheetResource extends JsonResource
|
|||
|
||||
/** @var array */
|
||||
private static $skeleton = [
|
||||
'id' => '',
|
||||
'label' => '',
|
||||
'slug' => '',
|
||||
'species' => null,
|
||||
'is_frenchpoultry' => false,
|
||||
'nutriscore' => [
|
||||
'id' => '',
|
||||
'label' => '',
|
||||
'slug' => '',
|
||||
'species' => null,
|
||||
'is_frenchpoultry' => false,
|
||||
'nutriscore' => [
|
||||
'label' => 'none',
|
||||
'value' => 0
|
||||
],
|
||||
'advantage' => '',
|
||||
'packaging' => [],
|
||||
'caliber' => [],
|
||||
'ingredients' => '',
|
||||
'preparation' => '',
|
||||
'sticker_sm' => '',
|
||||
'slider_pictures' => [],
|
||||
'subrange' => null,
|
||||
'advantage' => '',
|
||||
'packaging' => [],
|
||||
'caliber' => [],
|
||||
'ingredients' => '',
|
||||
'preparation' => '',
|
||||
'sticker_sm' => '',
|
||||
'nutritionnal_values' => [],
|
||||
'slider_pictures' => [],
|
||||
'subrange' => null,
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
@ -48,25 +48,27 @@ class ProductCommercialSheetResource extends JsonResource
|
|||
*
|
||||
* @param \Illuminate\Http\Request|null $request
|
||||
* @return array
|
||||
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
|
||||
*/
|
||||
public function toArray(?Request $request = null): array
|
||||
public function toArray($request = null)
|
||||
{
|
||||
return array_intersect_key(
|
||||
[
|
||||
'id' => $this->product->id,
|
||||
'label' => $this->product->label,
|
||||
'slug' => $this->product->slug,
|
||||
'species' => $this->product->species,
|
||||
'is_frenchpoultry' => $this->product->is_frenchpoultry,
|
||||
'nutriscore' => $this->product->nutriscore,
|
||||
'advantage' => $this->product->advantage,
|
||||
'packaging' => $this->product->packaging,
|
||||
'caliber' => $this->product->caliber,
|
||||
'ingredients' => $this->product->ingredients,
|
||||
'preparation' => $this->product->preparation,
|
||||
'sticker_sm' => $this->product->sticker_sm,
|
||||
'slider_pictures' => $this->product->slider_pictures,
|
||||
'subrange' => (new SubrangeResource($this->product->subrange))->toArray($request),
|
||||
'id' => $this->product->id,
|
||||
'label' => $this->product->label,
|
||||
'slug' => $this->product->slug,
|
||||
'species' => $this->product->species,
|
||||
'is_frenchpoultry' => $this->product->is_frenchpoultry,
|
||||
'nutriscore' => $this->product->nutriscore,
|
||||
'advantage' => $this->product->advantage,
|
||||
'packaging' => $this->product->packaging,
|
||||
'caliber' => $this->product->caliber,
|
||||
'ingredients' => $this->product->ingredients,
|
||||
'preparation' => $this->product->preparation,
|
||||
'nutritionnal_values' => $this->product->nutritionnal_values,
|
||||
'sticker_sm' => $this->product->sticker_sm,
|
||||
'slider_pictures' => $this->product->slider_pictures,
|
||||
'subrange' => (new SubrangeResource($this->product->subrange))->toArray($request),
|
||||
],
|
||||
$this->getSkeleton()
|
||||
);
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
namespace App\Http\Resources\Fo\Products;
|
||||
|
||||
use App\Models\Product;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\ResourceCollection;
|
||||
|
||||
class ProductPaginatedCollectionResource extends ResourceCollection
|
||||
|
|
@ -14,26 +13,27 @@ class ProductPaginatedCollectionResource extends ResourceCollection
|
|||
* @param \Illuminate\Http\Request $request
|
||||
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
|
||||
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
|
||||
* @phpcs:disable Squiz.Commenting.FunctionComment.TypeHintMissing
|
||||
*/
|
||||
public function toArray(Request $request): array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
|
||||
public function toArray($request)
|
||||
{
|
||||
//phpcs:enable
|
||||
// phpcs:enable
|
||||
/** @var \Illuminate\Pagination\LengthAwarePaginator */
|
||||
$paginator = $this->resource;
|
||||
return [
|
||||
'first_page_url' => $paginator->url(0),
|
||||
'current_page' => $paginator->currentPage(),
|
||||
'next_page_url' => $paginator->nextPageUrl(),
|
||||
'links' => $paginator->linkCollection(),
|
||||
'prev_page_url' => $paginator->previousPageUrl(),
|
||||
'last_page_url' => $paginator->url($paginator->lastPage()),
|
||||
'last_page' => $paginator->lastPage(),
|
||||
'per_page' => $paginator->perPage(),
|
||||
'total' => $paginator->total(),
|
||||
'path' => $paginator->path(),
|
||||
'from' => $paginator->firstItem(),
|
||||
'to' => $paginator->lastItem(),
|
||||
'data' => $this->collection->map(function (Product $product) {
|
||||
'current_page' => $paginator->currentPage(),
|
||||
'next_page_url' => $paginator->nextPageUrl(),
|
||||
'links' => $paginator->linkCollection(),
|
||||
'prev_page_url' => $paginator->previousPageUrl(),
|
||||
'last_page_url' => $paginator->url($paginator->lastPage()),
|
||||
'last_page' => $paginator->lastPage(),
|
||||
'per_page' => $paginator->perPage(),
|
||||
'total' => $paginator->total(),
|
||||
'path' => $paginator->path(),
|
||||
'from' => $paginator->firstItem(),
|
||||
'to' => $paginator->lastItem(),
|
||||
'data' => $this->collection->map(function (Product $product) {
|
||||
return new ProductResource($product);
|
||||
})
|
||||
];
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
namespace App\Http\Resources\Fo\Products;
|
||||
|
||||
use App\Models\Product;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class ProductResource extends JsonResource
|
||||
|
|
@ -13,14 +12,14 @@ class ProductResource extends JsonResource
|
|||
|
||||
/** @var array */
|
||||
private static $skeleton = [
|
||||
'id' => '',
|
||||
'label' => '',
|
||||
'slug' => '',
|
||||
'species' => null,
|
||||
'sticker_sm' => '',
|
||||
'sticker_sm_alt' => '',
|
||||
'id' => '',
|
||||
'label' => '',
|
||||
'slug' => '',
|
||||
'species' => null,
|
||||
'sticker_sm' => '',
|
||||
'sticker_sm_alt' => '',
|
||||
'sticker_sm_title' => '',
|
||||
'subrange' => null,
|
||||
'subrange' => null,
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
@ -39,19 +38,20 @@ class ProductResource extends JsonResource
|
|||
*
|
||||
* @param \Illuminate\Http\Request|null $request
|
||||
* @return array
|
||||
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
|
||||
*/
|
||||
public function toArray(?Request $request = null): array
|
||||
public function toArray($request = null)
|
||||
{
|
||||
return array_intersect_key(
|
||||
[
|
||||
'id' => $this->product->id,
|
||||
'label' => $this->product->label,
|
||||
'slug' => $this->product->slug,
|
||||
'species' => $this->product->species,
|
||||
'sticker_sm' => $this->product->sticker_sm,
|
||||
'sticker_sm_alt' => $this->product->sticker_sm_alt,
|
||||
'id' => $this->product->id,
|
||||
'label' => $this->product->label,
|
||||
'slug' => $this->product->slug,
|
||||
'species' => $this->product->species,
|
||||
'sticker_sm' => $this->product->sticker_sm,
|
||||
'sticker_sm_alt' => $this->product->sticker_sm_alt,
|
||||
'sticker_sm_title' => $this->product->sticker_sm_title,
|
||||
'subrange' => (new SubrangeResource($this->product->subrange))->toArray($request),
|
||||
'subrange' => (new SubrangeResource($this->product->subrange))->toArray($request),
|
||||
],
|
||||
$this->getSkeleton()
|
||||
);
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
namespace App\Http\Resources\Fo\Products;
|
||||
|
||||
use App\Models\Range;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class RangeResource extends JsonResource
|
||||
|
|
@ -13,9 +12,9 @@ class RangeResource extends JsonResource
|
|||
|
||||
/** @var array */
|
||||
private static $skeleton = [
|
||||
'id' => '',
|
||||
'id' => '',
|
||||
'label' => '',
|
||||
'slug' => '',
|
||||
'slug' => '',
|
||||
'color' => ''
|
||||
];
|
||||
|
||||
|
|
@ -37,14 +36,13 @@ class RangeResource extends JsonResource
|
|||
* @return array
|
||||
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
|
||||
*/
|
||||
public function toArray(?Request $request = null): array
|
||||
public function toArray($request = null)
|
||||
{
|
||||
//phpcs:enable
|
||||
return array_intersect_key(
|
||||
[
|
||||
'id' => $this->range->id,
|
||||
'id' => $this->range->id,
|
||||
'label' => $this->range->label,
|
||||
'slug' => $this->range->slug,
|
||||
'slug' => $this->range->slug,
|
||||
'color' => $this->range->color
|
||||
],
|
||||
$this->getSkeleton()
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
namespace App\Http\Resources\Fo\Products;
|
||||
|
||||
use App\Models\Subrange;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class SubrangeResource extends JsonResource
|
||||
|
|
@ -13,9 +12,9 @@ class SubrangeResource extends JsonResource
|
|||
|
||||
/** @var array */
|
||||
private static $skeleton = [
|
||||
'id' => '',
|
||||
'id' => '',
|
||||
'label' => '',
|
||||
'slug' => '',
|
||||
'slug' => '',
|
||||
'range' => null
|
||||
];
|
||||
|
||||
|
|
@ -35,8 +34,9 @@ class SubrangeResource extends JsonResource
|
|||
*
|
||||
* @param \Illuminate\Http\Request|null $request
|
||||
* @return array
|
||||
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
|
||||
*/
|
||||
public function toArray(?Request $request = null): array
|
||||
public function toArray($request = null)
|
||||
{
|
||||
return array_intersect_key(
|
||||
[
|
||||
|
|
@ -50,7 +50,7 @@ class SubrangeResource extends JsonResource
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the resource skeletton.
|
||||
* Returns the resource skeletton
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1,21 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Interfaces;
|
||||
|
||||
interface OrderableInterface
|
||||
{
|
||||
/**
|
||||
* Returns the priority order value.
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getPriorityOrder(): int;
|
||||
|
||||
/**
|
||||
* Returns the grouping field used for ordering.
|
||||
* Returns null if the order is global.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getOrderGroupField(): ?string;
|
||||
}
|
||||
|
|
@ -1,64 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Lib\Helpers;
|
||||
|
||||
use Illuminate\Container\Container;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Pagination\Paginator;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class CollectionHelper
|
||||
{
|
||||
/**
|
||||
* Paginate a collection
|
||||
*
|
||||
* @param \Illuminate\Support\Collection $results
|
||||
* @param integer $pageSize
|
||||
* @return \Illuminate\Pagination\LengthAwarePaginator
|
||||
*/
|
||||
public static function paginate(Collection $results, int $pageSize): LengthAwarePaginator
|
||||
{
|
||||
$page = Paginator::resolveCurrentPage('page');
|
||||
|
||||
return self::paginateManually($results, $pageSize, $page);
|
||||
}
|
||||
|
||||
/**
|
||||
* Paginate a collection
|
||||
*
|
||||
* @param \Illuminate\Support\Collection $results
|
||||
* @param integer $pageSize
|
||||
* @param integer $page
|
||||
* @return \Illuminate\Pagination\LengthAwarePaginator
|
||||
*/
|
||||
public static function paginateManually(Collection $results, int $pageSize, int $page = 1): LengthAwarePaginator
|
||||
{
|
||||
$total = $results->count();
|
||||
|
||||
return self::paginator($results->forPage($page, $pageSize), $total, $pageSize, $page, [
|
||||
'path' => Paginator::resolveCurrentPath(),
|
||||
'pageName' => 'page',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new length-aware paginator instance.
|
||||
*
|
||||
* @param \Illuminate\Support\Collection $items
|
||||
* @param integer $total
|
||||
* @param integer $perPage
|
||||
* @param integer $currentPage
|
||||
* @param array $options
|
||||
* @return \Illuminate\Pagination\LengthAwarePaginator
|
||||
*/
|
||||
protected static function paginator(Collection $items, int $total, int $perPage, int $currentPage, array $options)
|
||||
{
|
||||
return Container::getInstance()->makeWith(LengthAwarePaginator::class, [
|
||||
'items' => $items,
|
||||
'total' => $total,
|
||||
'perPage' => $perPage,
|
||||
'currentPage' => $currentPage,
|
||||
'options' => $options
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -80,13 +80,13 @@ class ExceptionsHelper
|
|||
foreach ($params as &$param) {
|
||||
$type = \strtolower(\gettype($param));
|
||||
if (\is_string($param)) {
|
||||
$type = \explode(' ', \trim(strtolower($param)))[0] ?? null;
|
||||
$type = \explode(' ', \trim($param))[0] ?? null;
|
||||
}
|
||||
switch (true) {
|
||||
case $type === 'lambda':
|
||||
case $type === 'object':
|
||||
switch ($type) {
|
||||
case 'Lambda':
|
||||
case 'Object':
|
||||
continue 2;
|
||||
case $type === 'array' and \is_array($param):
|
||||
case 'array':
|
||||
$param = sprintf('Array(%d)', \count($param));
|
||||
continue 2;
|
||||
default:
|
||||
|
|
@ -145,7 +145,7 @@ class ExceptionsHelper
|
|||
$traceStr .= self::handleArgs($stack);
|
||||
}
|
||||
$traceStr .= ")\n";
|
||||
} else {
|
||||
} elseif (isset($stack['function'])) {
|
||||
$traceStr .= "{$stack['function']}(";
|
||||
if (isset($stack['args'])) {
|
||||
$traceStr .= self::handleArgs($stack);
|
||||
|
|
|
|||
|
|
@ -30,20 +30,6 @@ use Illuminate\Support\Str;
|
|||
*/
|
||||
class FileStorageHelper
|
||||
{
|
||||
/**
|
||||
* Remove all files from string attribute html that are stored in public
|
||||
*
|
||||
* @param string $publicStorageFilePath The file path from public directory.
|
||||
* @return string The local storage path.
|
||||
*/
|
||||
public static function getFileFullPath(string $publicStorageFilePath): string
|
||||
{
|
||||
/** @var \Illuminate\Filesystem\FilesystemAdapter */
|
||||
$disk = Storage::disk('uploads');
|
||||
$path = ToolboxHelper::mbReplace('storage/', '', \ltrim(\urldecode($publicStorageFilePath), '/'));
|
||||
return $disk->path($path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy the file associate with the attribute.
|
||||
*
|
||||
|
|
@ -63,20 +49,6 @@ class FileStorageHelper
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy files associate with the attribute.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Model $model
|
||||
* @param array $array
|
||||
* @return void
|
||||
*/
|
||||
public static function removeFiles(Model $model, array $array): void
|
||||
{
|
||||
foreach ($array as $item) {
|
||||
self::removeFile($model, $item);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy the file associate with the attribute old value (before updated to DB).
|
||||
*
|
||||
|
|
@ -88,10 +60,10 @@ class FileStorageHelper
|
|||
public static function removeOldFile(Model $model, string $attribute, bool $onlyIfUpdated = true): void
|
||||
{
|
||||
// * Ignore If removal has to be done only if the field has changed and it actually hasnt.
|
||||
if ($onlyIfUpdated and $model->{$attribute} === ToolboxHelper::getOriginal($model, $attribute)) {
|
||||
if ($onlyIfUpdated and $model->{$attribute} === $model->getOriginal($attribute)) {
|
||||
return;
|
||||
}
|
||||
$originalPath = \ltrim(\urldecode(ToolboxHelper::getOriginal($model, $attribute)), '/');
|
||||
$originalPath = \ltrim(\urldecode($model->getOriginal($attribute)), '/');
|
||||
if (\strpos($originalPath, 'storage') !== 0) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -110,48 +82,29 @@ class FileStorageHelper
|
|||
* @param \Illuminate\Http\UploadedFile|\SplFileInfo|string $file The file, will just return itself is string.
|
||||
* @param boolean $slugify Force filename slugification.
|
||||
* @param string|null $filename This string may be used to store the file.
|
||||
* @param boolean $private To store the file in a private space.
|
||||
* @return string
|
||||
* @throws \RuntimeException If file copy fails.
|
||||
* @phpcs:disable Generic.Metrics.CyclomaticComplexity.TooHigh
|
||||
*/
|
||||
public static function storeFile(
|
||||
Model $model,
|
||||
$file,
|
||||
bool $slugify = false,
|
||||
string|null $filename = null,
|
||||
bool $private = false
|
||||
): string {
|
||||
// phpcs:enable
|
||||
public static function storeFile(Model $model, $file, bool $slugify = false, string $filename = null): string
|
||||
{
|
||||
$tableName = $model->getTable();
|
||||
if (\is_object($file) and $file instanceof \Illuminate\Http\UploadedFile) {
|
||||
/** @var \Illuminate\Http\UploadedFile $file */
|
||||
$filename = $filename ?: $file->getClientOriginalName();
|
||||
$filename = $slugify ? self::slugifyFileName($filename) : $filename;
|
||||
$newPath = self::prepareMoveFile($tableName, $filename, $private);
|
||||
$newPath = self::prepareMoveFile($tableName, $filename);
|
||||
$newPath = str_replace(storage_path('app'), '', $newPath);
|
||||
|
||||
if (!$private) {
|
||||
// * Store public file.
|
||||
$file->storePubliclyAs(
|
||||
pathinfo($newPath, \PATHINFO_DIRNAME),
|
||||
pathinfo($newPath, \PATHINFO_BASENAME)
|
||||
);
|
||||
return 'storage' . str_replace('/public', '', $newPath);
|
||||
}
|
||||
|
||||
$file->storeAs(
|
||||
$file->storePubliclyAs(
|
||||
pathinfo($newPath, \PATHINFO_DIRNAME),
|
||||
pathinfo($newPath, \PATHINFO_BASENAME)
|
||||
);
|
||||
|
||||
return str_replace('/private/', '', $newPath);
|
||||
} //end if
|
||||
return 'storage' . str_replace('/public', '', $newPath);
|
||||
}
|
||||
if (\is_object($file) and $file instanceof \SplFileInfo) {
|
||||
/** @var \SplFileInfo $file */
|
||||
$filename = $filename ?: $file->getBaseName();
|
||||
$filename = $slugify ? self::slugifyFileName($filename) : $filename;
|
||||
$newPath = self::prepareMoveFile($tableName, $filename, $private);
|
||||
$newPath = self::prepareMoveFile($tableName, $filename);
|
||||
if (!File::copy($file->getRealPath(), $newPath)) {
|
||||
throw new \RuntimeException(sprintf(
|
||||
'Failed to copy file %s to %s',
|
||||
|
|
@ -159,9 +112,7 @@ class FileStorageHelper
|
|||
$newPath
|
||||
));
|
||||
}
|
||||
return $private ?
|
||||
\ltrim(str_replace(\storage_path('app/private'), '/storage/app/private', $newPath), '/') :
|
||||
\ltrim(str_replace(\storage_path('app/public'), '/storage', $newPath), '/');
|
||||
return \ltrim(str_replace(\storage_path('app/public'), '/storage', $newPath), '/');
|
||||
}
|
||||
return strval($file);
|
||||
}
|
||||
|
|
@ -171,6 +122,7 @@ class FileStorageHelper
|
|||
* If oldHtmlString is passed, a diff is done with new and old files
|
||||
* to keep only files that are present in the new html string.
|
||||
*
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Model $model The model that will hold the picture.
|
||||
* @param string $htmlString The html string to parse and modify files.
|
||||
* @param string|null $oldHtmlString The old html string with alreadyParsed
|
||||
|
|
@ -180,7 +132,7 @@ class FileStorageHelper
|
|||
public static function storeModelFilesFromHtml(
|
||||
Model $model,
|
||||
string $htmlString,
|
||||
string|null $oldHtmlString = null
|
||||
string $oldHtmlString = null
|
||||
): string {
|
||||
\collect(self::onlyUploadedFilesWithFileManager(self::findFilesInHtml($htmlString)))
|
||||
->each(function (string $path) use ($model, &$htmlString) {
|
||||
|
|
@ -256,7 +208,6 @@ class FileStorageHelper
|
|||
|
||||
/**
|
||||
* Find all occurence of files in html
|
||||
*
|
||||
* @param string $html
|
||||
* @return array
|
||||
*/
|
||||
|
|
@ -317,27 +268,22 @@ class FileStorageHelper
|
|||
* Prepare storage path and return
|
||||
* the file full path
|
||||
*
|
||||
* @param string $tableName Model table name.
|
||||
* @param string $filename The basename for the file.
|
||||
* @param boolean $private May the file be stored in a private dir.
|
||||
* @param string $tableName Model table name.
|
||||
* @param string $filename The basename for the file.
|
||||
* @return string
|
||||
*/
|
||||
private static function prepareMoveFile(string $tableName, string $filename, bool $private = false): string
|
||||
private static function prepareMoveFile(string $tableName, string $filename): string
|
||||
{
|
||||
// * Security filter
|
||||
$filename = \htmlspecialchars($filename);
|
||||
// * Security filter + beautifier
|
||||
$filename = self::sanitizeFileName($filename);
|
||||
// * Security filter
|
||||
$filename = \filter_var($filename, \FILTER_SANITIZE_STRING);
|
||||
// * Slugify filename
|
||||
$ext = \pathinfo($filename, \PATHINFO_EXTENSION);
|
||||
$filename = Str::slug(\pathinfo($filename, \PATHINFO_FILENAME)) .
|
||||
(\strlen($ext) ? ".{$ext}" : '');
|
||||
|
||||
$folderPath = self::getStoragePath(
|
||||
$private ? 'app/private/modelfiles' : 'app/public/modelfiles',
|
||||
$tableName,
|
||||
$filename
|
||||
);
|
||||
$folderPath = self::getStoragePath($tableName, $filename);
|
||||
$filename = self::getFileUniqueName($folderPath, $filename);
|
||||
return "{$folderPath}/{$filename}";
|
||||
}
|
||||
|
|
@ -347,17 +293,15 @@ class FileStorageHelper
|
|||
* storage/modelfiles/posts/10/04/19/5f
|
||||
* year/month/day/md5 first 2 letters
|
||||
*
|
||||
* @param string $storage_dir
|
||||
* @param string $table
|
||||
* @param string $filename
|
||||
* @return string
|
||||
*/
|
||||
private static function getStoragePath(string $storage_dir, string $table, string $filename): string
|
||||
private static function getStoragePath(string $table, string $filename): string
|
||||
{
|
||||
$filenameHash = \md5($filename);
|
||||
$pathFolder = \storage_path(sprintf(
|
||||
'%s/%s/%s/%s/%s/%s',
|
||||
$storage_dir,
|
||||
'app/public/modelfiles/%s/%s/%s/%s/%s',
|
||||
$table,
|
||||
gmdate('y'),
|
||||
gmdate('m'),
|
||||
|
|
@ -384,7 +328,7 @@ class FileStorageHelper
|
|||
$maxAttempts = 20;
|
||||
while (File::exists("{$folderPath}/{$filename}")) {
|
||||
if ($attempts++ >= $maxAttempts) {
|
||||
throw new \RuntimeException("Failed to have a unique filename for {$folderPath}/{$filename}");
|
||||
throw new \RuntimeException("Failed to has a unique filename for {$folderPath}/{$filename}");
|
||||
}
|
||||
$filename = pathinfo($filename, \PATHINFO_FILENAME) .
|
||||
\uniqid('-') . '.' .
|
||||
|
|
@ -431,7 +375,7 @@ class FileStorageHelper
|
|||
$filename = Str::of($filename)->ltrim('.-');
|
||||
// * Optional beautification
|
||||
if ($beautify) {
|
||||
$filename = self::beautifyFilename($filename);
|
||||
$filename = static::beautifyFilename($filename);
|
||||
}
|
||||
// * Maximize filename length to 255 bytes http://serverfault.com/a/9548/44086
|
||||
/** @var string */
|
||||
|
|
@ -478,4 +422,39 @@ class FileStorageHelper
|
|||
$filename = trim($filename, '.-');
|
||||
return $filename;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store picture array
|
||||
* @param \Illuminate\Database\Eloquent\Model $model
|
||||
* @param array $files
|
||||
* @return array Containing stored Files using storage strategy.
|
||||
*/
|
||||
public static function storePictureArray(Model $model, array $files): array
|
||||
{
|
||||
return \collect($files)->map(function ($file) use ($model) {
|
||||
if (!\is_string($file) and !(\is_object($file) and $file instanceof \SplFileInfo)) {
|
||||
throw new \RuntimeException('picture array does not support anything else than string or SplfFileInfo');
|
||||
}
|
||||
return FileStorageHelper::storeFile($model, $file, true);
|
||||
})->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove picture array
|
||||
* @param \Illuminate\Database\Eloquent\Model $model
|
||||
* @param array $files
|
||||
* @return void
|
||||
*/
|
||||
public static function removePictureArray(Model $model, array $files): void
|
||||
{
|
||||
\collect($files)->map(function ($file) use ($model) {
|
||||
if (!\is_string($file)) {
|
||||
throw new \RuntimeException('picture array does not support anything else than string');
|
||||
}
|
||||
// * Use temp prop te remove file.
|
||||
$model->tempPicture = $file;
|
||||
FileStorageHelper::removeFile($model, 'tempPicture');
|
||||
$model->tempPicture = null;
|
||||
})->all();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,128 +2,44 @@
|
|||
|
||||
namespace App\Lib\Helpers;
|
||||
|
||||
use App\Enums\Pagination\ItemsPerPaginationEnum;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Contracts\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Validation\Rules\Enum;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Symfony\Component\Finder\SplFileInfo;
|
||||
|
||||
class ToolboxHelper
|
||||
{
|
||||
/**
|
||||
* Run a terminal command and gives the output
|
||||
* Cut string words
|
||||
*
|
||||
* @param array|string $command The command to execute on terminal.
|
||||
* @param boolean $throw Wether to throw en esception on failure or not.
|
||||
* @return string|false Return false on failure only if $throw is false.
|
||||
* @phpcs:disable Squiz.Commenting.FunctionComment.EmptyThrows
|
||||
* @phpcs:disable Squiz.Commenting.FunctionCommentThrowTag.WrongNumber
|
||||
* @throws \Illuminate\Process\Exceptions\ProcessTimedOutException
|
||||
* @throws \Symfony\Component\Process\Exception\LogicException
|
||||
* @throws \Symfony\Component\Process\Exception\InvalidArgumentException
|
||||
* @throws \Symfony\Component\Process\Exception\RuntimeException
|
||||
* @throws \LogicException
|
||||
* @throws \RuntimeException If the command fails.
|
||||
* @param string $string
|
||||
* @param integer $max
|
||||
* @param string $hyphen
|
||||
* @return string
|
||||
*/
|
||||
public static function runConsoleCommand(array|string $command, bool $throw = true): string | false
|
||||
public static function cutWords(string $string, int $max = 20, string $hyphen = '[.]')
|
||||
{
|
||||
// phpcs:enable
|
||||
$process = \Illuminate\Support\Facades\Process::command($command)->run();
|
||||
if ($process->failed()) {
|
||||
$code = $process->exitCode();
|
||||
$ouput = $process->errorOutput();
|
||||
if ($throw) {
|
||||
throw new \RuntimeException("Failed to run command exit code {$code} with output \n{$ouput}");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return $process->output();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int|string, mixed> $array1
|
||||
* @param array<int|string, mixed> $array2
|
||||
*
|
||||
* @return array<int|string, mixed>
|
||||
*/
|
||||
public static function arrayMergeRecursiveDistinct(array &$array1, array &$array2): array
|
||||
{
|
||||
$merged = $array1;
|
||||
foreach ($array2 as $key => &$value) {
|
||||
if (is_array($value) && isset($merged[$key]) && is_array($merged[$key])) {
|
||||
$merged[$key] = self::arrayMergeRecursiveDistinct($merged[$key], $value);
|
||||
$originalString = $string;
|
||||
$tok = strtok($string, ' ');
|
||||
$string = '';
|
||||
while ($tok !== false && mb_strlen($string) < $max) {
|
||||
if (
|
||||
mb_strlen($string) + mb_strlen($tok) <= $max
|
||||
) {
|
||||
$string .= $tok . ' ';
|
||||
} else {
|
||||
$merged[$key] = $value;
|
||||
break;
|
||||
}
|
||||
$tok = strtok(' ');
|
||||
}
|
||||
|
||||
return $merged;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate recaptcha
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param boolean $isV3
|
||||
* @return void
|
||||
*/
|
||||
public static function validateRecaptcha(Request $request, bool $isV3 = true)
|
||||
{
|
||||
Validator::validate($request->all(), [
|
||||
'g-recaptcha-response' => [
|
||||
'required', 'string',
|
||||
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed, Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed
|
||||
function ($attribute, $value, $fail) use ($isV3) {
|
||||
try {
|
||||
$response = Http::asForm()->post('https://www.google.com/recaptcha/api/siteverify', [
|
||||
'secret' => config('services.google.recaptcha.private'),
|
||||
'response' => \strval($value),
|
||||
'remoteip' => app('clientIp')
|
||||
]);
|
||||
if ($e = $response->toException()) {
|
||||
throw $e;
|
||||
}
|
||||
if ($isV3) {
|
||||
if (
|
||||
!$response->json('success') or
|
||||
!$response->json('challenge_ts') or
|
||||
Carbon::parse($response->json('challenge_ts'))->lessThan(\now('utc')->subMinutes(5)) or
|
||||
$response->json('hostname') !== \parse_url(config('app.url'), \PHP_URL_HOST) or
|
||||
!$response->json('score')
|
||||
) {
|
||||
throw new \RuntimeException();
|
||||
}
|
||||
if (\floatval($response->json('score')) < 0.8) {
|
||||
$fail(trans('recaptcha.not_enough_score'));
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (
|
||||
!$response->json('success') or
|
||||
!$response->json('challenge_ts') or
|
||||
Carbon::parse($response->json('challenge_ts'))->lessThan(\now('utc')->subMinutes(5)) or
|
||||
$response->json('hostname') !== \parse_url(config('app.url'), \PHP_URL_HOST)
|
||||
) {
|
||||
throw new \RuntimeException();
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$fail(trans('recaptcha.error'));
|
||||
} //end try
|
||||
}
|
||||
]
|
||||
], [], ['g-recaptcha-response' => 'reCaptcha']);
|
||||
return trim($string) . (strlen(trim($string)) !== strlen(trim($originalString)) ? $hyphen : '');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -169,10 +85,7 @@ class ToolboxHelper
|
|||
) {
|
||||
// Removes the matched url.
|
||||
throw ValidationException::withMessages([
|
||||
$field => trans(
|
||||
'crud.libs.toolbox.assertNoInternalBoUrls',
|
||||
['attribute' => $field]
|
||||
)
|
||||
$field => ':attribute : Il est interdit de coller une url du back office dans ce champ'
|
||||
]);
|
||||
}
|
||||
return $match;
|
||||
|
|
@ -206,15 +119,16 @@ class ToolboxHelper
|
|||
$url = $match;
|
||||
try {
|
||||
$request = Request::create($url);
|
||||
// Assert route matches existing routes.
|
||||
$routes->match($request);
|
||||
// ? Is url internal ?
|
||||
if (\parse_url(config('app.url'), \PHP_URL_HOST) === \parse_url($url, \PHP_URL_HOST)) {
|
||||
// If a route is match then it do not throws exception.
|
||||
if (
|
||||
\parse_url(config('app.url'), \PHP_URL_HOST) === \parse_url($url, \PHP_URL_HOST) &&
|
||||
$routes->match($request)
|
||||
) {
|
||||
// Removes the matched url.
|
||||
throw ValidationException::withMessages([
|
||||
$field => trans(
|
||||
'crud.libs.toolbox.assertNoInternalUrls',
|
||||
['attribute' => $field, 'appname' => config('app.name')]
|
||||
$field => sprintf(
|
||||
':attribute : Il est interdit de coller une url de %s dans ce champ',
|
||||
config('app.name')
|
||||
)
|
||||
]);
|
||||
}
|
||||
|
|
@ -229,20 +143,56 @@ class ToolboxHelper
|
|||
}
|
||||
|
||||
/**
|
||||
* Mutltibyte string replace
|
||||
* Generate url using laravel route passing our group query if present
|
||||
* This is used to keep ou group tracking
|
||||
* Curd-policies is only used for root users as it cannot keep track of our group
|
||||
* and validate things
|
||||
*
|
||||
* @param array|string $search
|
||||
* @param array|string $replace
|
||||
* @param array|string $subject
|
||||
* @param integer $count
|
||||
* @return array|string|false
|
||||
* @param array|string $name
|
||||
* @param mixed $parameters
|
||||
* @param boolean $absolute
|
||||
* @return string
|
||||
* @throws \ErrorException If an object given as parameter is not a Model.
|
||||
*/
|
||||
public static function mbReplace(
|
||||
array|string $search,
|
||||
array|string $replace,
|
||||
array|string $subject,
|
||||
int &$count = 0
|
||||
): array|string|false {
|
||||
public static function routeWithGroup($name, $parameters = [], bool $absolute = true): string
|
||||
{
|
||||
// * Handle if parameter if is an object.
|
||||
if (\is_object($parameters)) {
|
||||
$parents = \class_parents($parameters);
|
||||
if ($parents === false or !\in_array(Model::class, $parents)) {
|
||||
throw new \ErrorException(\sprintf(
|
||||
'%s only support object of type %s',
|
||||
__FUNCTION__,
|
||||
Model::class
|
||||
));
|
||||
}
|
||||
/** @var \Illuminate\Database\Eloquent\Model $model */
|
||||
$model = $parameters;
|
||||
$parameters = [Str::singular($model->getTable()) => $model];
|
||||
}
|
||||
// * Handle if parameter isnt and array like slug or else.
|
||||
if (!is_array($parameters)) {
|
||||
// * Best effort, result is not garantee.
|
||||
$parameters = [$parameters];
|
||||
}
|
||||
// * Pass our group.
|
||||
if ($group = Session::get('activeGroup', request()->group)) {
|
||||
$parameters = array_merge($parameters, ['group' => $group]);
|
||||
}
|
||||
// * Call laravel route helper.
|
||||
return route($name, $parameters, $absolute);
|
||||
}
|
||||
|
||||
/**
|
||||
* Mutltibyte string replace
|
||||
* @param mixed $search
|
||||
* @param mixed $replace
|
||||
* @param mixed $subject
|
||||
* @param integer $count
|
||||
* @return mixed
|
||||
*/
|
||||
public static function mbReplace($search, $replace, $subject, int &$count = 0)
|
||||
{
|
||||
if (!is_array($search) && is_array($replace)) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -275,318 +225,142 @@ class ToolboxHelper
|
|||
/**
|
||||
* Asserts that the field is unique
|
||||
*
|
||||
* @param string $table
|
||||
* @param string $field
|
||||
* @param string|integer|float|boolean|null|array $value
|
||||
* @param integer|null $id
|
||||
* @param callable|null $query
|
||||
* @param string $table
|
||||
* @param string $field
|
||||
* @param mixed $value
|
||||
* @param integer|null $id
|
||||
* @param callable|null $query
|
||||
* @return void
|
||||
* @throws \Illuminate\Validation\ValidationException If the field is not unique.
|
||||
*/
|
||||
public static function assertFieldIsUnique(
|
||||
string $table,
|
||||
string $field,
|
||||
string|int|float|bool|null|array $value,
|
||||
$value,
|
||||
?int $id = null,
|
||||
?callable $query = null
|
||||
) {
|
||||
if (!$query) {
|
||||
Validator::make([$field => $value], [
|
||||
self::mbReplace('.', '\.', $field) => Rule::unique($table, $field)->ignore($id),
|
||||
$field => Rule::unique($table, $field)->ignore($id),
|
||||
], [
|
||||
self::mbReplace('.', '\.', "{$field}.unique")
|
||||
=> trans('crud.libs.toolbox.assertFieldIsUnique', ['attribute' => $field, 'value' => $value])
|
||||
$field . '.unique' => trans('La valeur :value pour le champ :attribute est déjà utilisé', [
|
||||
'attribute' => $field,
|
||||
'value' => $value
|
||||
])
|
||||
])->validate();
|
||||
return;
|
||||
}
|
||||
Validator::make([$field => $value], [
|
||||
$field => Rule::unique($table)->where($query)->ignore($id),
|
||||
], [
|
||||
$field . '.unique' => trans(
|
||||
'crud.libs.toolbox.assertFieldIsUnique',
|
||||
['attribute' => $field, 'value' => $value]
|
||||
)
|
||||
$field . '.unique' => trans('La valeur pour le champ :attribute est déjà utilisé', [
|
||||
'attribute' => $field
|
||||
])
|
||||
])->validate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get original polyfill with autotranslate behavior
|
||||
* Check that two arrays have the same content (1 level only)
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Model $model
|
||||
* @param string $attribute
|
||||
* @return mixed
|
||||
* @param array $array1
|
||||
* @param array $array2
|
||||
* @return boolean
|
||||
*/
|
||||
public static function getOriginal(Model $model, string $attribute): mixed
|
||||
public static function arrayHaveSameContent(array $array1, array $array2): bool
|
||||
{
|
||||
if (
|
||||
\in_array('Spatie\Translatable\HasTranslations', \class_uses_recursive($model)) and
|
||||
// @phpstan-ignore-next-line
|
||||
$model->isTranslatableAttribute($attribute)
|
||||
) {
|
||||
// @phpstan-ignore-next-line
|
||||
return $model->getTranslation(
|
||||
$attribute,
|
||||
// @phpstan-ignore-next-line
|
||||
$model->getLocale(),
|
||||
// @phpstan-ignore-next-line
|
||||
$model->useFallbackLocale()
|
||||
);
|
||||
}
|
||||
return $model->getOriginal($attribute);
|
||||
return (array_diff($array1, $array2) == [] && array_diff($array2, $array1) == []);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamic model query
|
||||
* * Register CSP report URI
|
||||
*
|
||||
* @param string $defaultLocale
|
||||
* @param \Illuminate\Contracts\Database\Eloquent\Builder $q
|
||||
* @param string $column
|
||||
* @param string $value
|
||||
* @return \Illuminate\Contracts\Database\Eloquent\Builder
|
||||
*/
|
||||
public static function queryColumnWithLocales(
|
||||
string $defaultLocale,
|
||||
Builder $q,
|
||||
string $column,
|
||||
string $value
|
||||
): Builder {
|
||||
$currentLocale = app()->currentLocale();
|
||||
$locales = collect(config('app.locales'))
|
||||
->mapWithKeys(fn (string $locale) => [$locale => $locale]);
|
||||
if (!$locales->has($defaultLocale)) {
|
||||
// * Remove default locale.
|
||||
$locales->pull($defaultLocale);
|
||||
}
|
||||
if (!$locales->has($currentLocale)) {
|
||||
// * Remove current locale.
|
||||
$locales->pull($currentLocale);
|
||||
}
|
||||
|
||||
return $q->where(function (Builder $q) use ($defaultLocale, $currentLocale, $locales, $column, $value) {
|
||||
// * Query default locale
|
||||
$q->whereRaw("JSON_EXTRACT({$column}, '$.{$defaultLocale}') = '{$value}'");
|
||||
if ($defaultLocale !== $currentLocale) {
|
||||
// * Query current locale
|
||||
$q->whereRaw("JSON_EXTRACT({$column}, '$.{$currentLocale}') = '{$value}'");
|
||||
}
|
||||
// * Query any other locale
|
||||
$locales->each(fn ($locale) => $q->orWhereRaw(
|
||||
"JSON_EXTRACT({$column}, '$.{$locale}') = '{$value}'"
|
||||
));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates an array from a dot separated string
|
||||
* Put this function inside RouteServiceProvider,
|
||||
* and call it in RouteServiceProvider::boot
|
||||
*
|
||||
* @param string $path
|
||||
* @param mixed $value
|
||||
* @param string $separator
|
||||
* @return array
|
||||
*/
|
||||
public static function dotStringToNestedArray(string $path, mixed $value, string $separator = '.'): array
|
||||
{
|
||||
$arr = $value;
|
||||
$keys = array_reverse(explode($separator, $path));
|
||||
|
||||
foreach ($keys as $key) {
|
||||
$arr = [$key => $arr];
|
||||
}
|
||||
return $arr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert deeply an object to array
|
||||
* ! Use this in conjonction with kwaadpepper/exception-handler
|
||||
*
|
||||
* @param mixed $input
|
||||
* @return array
|
||||
* @throws \RuntimeException If $input var is a scalar value.
|
||||
*/
|
||||
public static function objectToArray(mixed $input): array
|
||||
{
|
||||
// Only process if it's an object or array being passed to the function.
|
||||
if (!(is_object($input) or is_array($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
|
||||
*
|
||||
* @param mixed $input
|
||||
* @return object
|
||||
* @throws \RuntimeException If $input var is a scalar value.
|
||||
*/
|
||||
public static function arrayToObject(mixed $input): object
|
||||
{
|
||||
// Only process if it's an object or array being passed to the function.
|
||||
if (!(is_object($input) or is_array($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
|
||||
*
|
||||
* @param string $attribute
|
||||
* @param string|null $value
|
||||
* @param callable $fail
|
||||
* @param object $sizes
|
||||
* @return void
|
||||
*/
|
||||
public static function validatePicture(string $attribute, string|null $value, callable $fail, object $sizes): void
|
||||
public static function cspReportRoute()
|
||||
{
|
||||
if (!($useStorage = Storage::exists($value)) and !File::exists($value)) {
|
||||
$fail(trans(':attribute n\'existe pas dans le système de fichier', [
|
||||
'attribute' => $attribute
|
||||
// * CSP REPORT URI, Please add /csp-report to VerifyCsrfToken $except middleware
|
||||
\Illuminate\Support\Facades\Route::post('/csp-report', function () {
|
||||
$isCspRequest = request()->header('Content-Type') === 'application/csp-report';
|
||||
if (!$isCspRequest or !request()->json('csp-report') or !is_array(request()->json('csp-report'))) {
|
||||
abort(401);
|
||||
}
|
||||
// * Flatten if needed
|
||||
$cspReport = collect(request()->json('csp-report'))
|
||||
->flatMap(function ($v, $k) {
|
||||
return [$k => is_array($v) ? collect($v)->flatten()->implode(', ') : $v];
|
||||
})->all();
|
||||
// * Filter array keys
|
||||
$cspReport = collect(array_intersect_key($cspReport, [
|
||||
'blocked-uri' => '', 'document-uri' => '', 'original-policy' => '',
|
||||
'referrer' => '', 'violated-directive' => ''
|
||||
]));
|
||||
return;
|
||||
}
|
||||
$fileFullPath = self::getUploadedFileFullPath($value, $useStorage);
|
||||
if (
|
||||
!\in_array(self::getUploadedFileMimeType($value, $useStorage), [
|
||||
'image/jpeg', 'image/jpg', 'image/png', 'image/gif'
|
||||
])
|
||||
) {
|
||||
$fail(trans(':attribute doit être une image de type \'image/jpeg,image/jpg,image/png,image/gif\'', [
|
||||
'attribute' => $attribute
|
||||
]));
|
||||
}
|
||||
if (!($dimensions = \getimagesize($fileFullPath))) {
|
||||
$fail(trans(':attribute impossible de valider les dimensions', [
|
||||
'attribute' => $attribute
|
||||
]));
|
||||
} else {
|
||||
$width = intval($dimensions[0]);
|
||||
$height = intval($dimensions[1]);
|
||||
|
||||
$xMessage = trans(
|
||||
":attribute la largeur doit être comprise entre {$sizes->minWidth}px et {$sizes->maxWidth}px"
|
||||
);
|
||||
if ($sizes->minWidth === $sizes->maxWidth) {
|
||||
$xMessage = trans(":attribute la largeur doit être de {$sizes->minWidth}px");
|
||||
}
|
||||
$yMessage = trans(
|
||||
":attribute la hauteur doit être comprise entre {$sizes->minWidth}px et {$sizes->maxWidth}px"
|
||||
);
|
||||
if ($sizes->minHeight === $sizes->maxHeight) {
|
||||
$yMessage = trans(":attribute la hauteur doit être de {$sizes->minHeight}px");
|
||||
}
|
||||
|
||||
if (($width < $sizes->minWidth) or ($width > $sizes->maxWidth)) {
|
||||
$fail($xMessage);
|
||||
}
|
||||
if (($height < $sizes->minHeight) or ($height > $sizes->maxHeight)) {
|
||||
$fail($yMessage);
|
||||
}
|
||||
} //end if
|
||||
report(new \Illuminate\Http\Client\HttpClientException(sprintf(
|
||||
"CSP REPORT for %s : \n %s",
|
||||
$cspReport->get('document-uri'),
|
||||
$cspReport->implode("\n")
|
||||
)));
|
||||
})->middleware('throttle:5,2')
|
||||
->withoutMiddleware(\App\Http\Middleware\VerifyCsrfToken::class)
|
||||
->name('cspReportUri');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the file full path
|
||||
* Validate recaptcha
|
||||
*
|
||||
* @param string $value
|
||||
* @param boolean $useStorage
|
||||
* @return string
|
||||
* @param Request $request
|
||||
* @param boolean $isV3
|
||||
* @return void
|
||||
*/
|
||||
private static function getUploadedFileFullPath(string $value, bool $useStorage): string
|
||||
public static function validateRecaptcha(Request $request, bool $isV3 = true)
|
||||
{
|
||||
/** @var \Illuminate\Filesystem\FilesystemAdapter */
|
||||
$disk = Storage::disk();
|
||||
return !$useStorage ? (realpath($value) ?: $value) : $disk->path($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the file mimetype
|
||||
*
|
||||
* @param string $value
|
||||
* @param boolean $useStorage
|
||||
* @return string|false
|
||||
*/
|
||||
private static function getUploadedFileMimeType(string $value, bool $useStorage)
|
||||
{
|
||||
return !$useStorage ? File::mimeType($value) : Storage::mimeType($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch class list from a specific namespace
|
||||
*
|
||||
* @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)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get validated pagination from request.
|
||||
*
|
||||
* @param integer $default
|
||||
* @param string $field
|
||||
* @param string $enumPath
|
||||
* @return integer
|
||||
*/
|
||||
public static function getValidatedEnum(int $default, string $field, string $enumPath): int
|
||||
{
|
||||
try {
|
||||
return \intval(Validator::make(
|
||||
[$field => \request()->get($field)],
|
||||
[$field => new Enum($enumPath)]
|
||||
)->validated()[$field]);
|
||||
} catch (ValidationException $e) {
|
||||
return $default;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get validated pagination from request.
|
||||
*
|
||||
* @param integer $default
|
||||
* @return integer
|
||||
*/
|
||||
public static function getValidatedPaginate(int $default): int
|
||||
{
|
||||
try {
|
||||
return \intval(Validator::make(
|
||||
['pagination' => \request()->get('pagination')],
|
||||
['pagination' => new Enum(ItemsPerPaginationEnum::class)]
|
||||
)->validated()['pagination']);
|
||||
} catch (ValidationException $e) {
|
||||
return $default;
|
||||
}
|
||||
Validator::validate($request->all(), [
|
||||
'g-recaptcha-response' => [
|
||||
'required', 'string',
|
||||
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed, Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed
|
||||
function ($attribute, $value, $fail) use ($isV3) {
|
||||
try {
|
||||
$response = Http::asForm()->post('https://www.google.com/recaptcha/api/siteverify', [
|
||||
'secret' => config('services.google.recaptcha.private'),
|
||||
'response' => \strval($value),
|
||||
'remoteip' => app('clientIp')
|
||||
]);
|
||||
if ($e = $response->toException()) {
|
||||
throw $e;
|
||||
}
|
||||
if ($isV3) {
|
||||
if (
|
||||
!$response->json('success') or
|
||||
!$response->json('challenge_ts') or
|
||||
Carbon::parse($response->json('challenge_ts'))->lessThan(\now('utc')->subMinutes(5)) or
|
||||
$response->json('hostname') !== \parse_url(config('app.url'), \PHP_URL_HOST) or
|
||||
!$response->json('score')
|
||||
) {
|
||||
throw new \RuntimeException();
|
||||
}
|
||||
if (\floatval($response->json('score')) < 0.8) {
|
||||
$fail("Vous n'avez pas obtenu un score assez élevé lors de la validation du recaptcha");
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (
|
||||
!$response->json('success') or
|
||||
!$response->json('challenge_ts') or
|
||||
Carbon::parse($response->json('challenge_ts'))->lessThan(\now('utc')->subMinutes(5)) or
|
||||
$response->json('hostname') !== \parse_url(config('app.url'), \PHP_URL_HOST)
|
||||
) {
|
||||
throw new \RuntimeException();
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$fail('Erreur lors de la validation du formulaire veuillez réssayer');
|
||||
} //end try
|
||||
}
|
||||
]
|
||||
], [], ['g-recaptcha-response' => 'reCaptcha']);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,8 +30,8 @@ class ContactFormMail extends Mailable
|
|||
*/
|
||||
public function build()
|
||||
{
|
||||
return $this->from(config('mail.from.address'))
|
||||
->subject(sprintf("%s : %s", config('app.name'), trans("Nouveau contact")))
|
||||
->markdown('fo.emails.contact-form', $this->request->toArray());
|
||||
return $this->from(config('mail.contactsList.contactform'))
|
||||
->subject(sprintf("%s : %s", config('app.name'), trans("Nouveau contact")))
|
||||
->markdown('fo.emails.contact-form', $this->request->toArray());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,73 +2,22 @@
|
|||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Interfaces\OrderableInterface;
|
||||
use App\Enums\Advices\AdviceDifficultyEnum;
|
||||
use App\Enums\Advices\AdviceTypeEnum;
|
||||
use App\Enums\Advices\AdviceDifficultyEnum;
|
||||
use App\Lib\Helpers\FileStorageHelper;
|
||||
use App\Lib\Helpers\ToolboxHelper;
|
||||
use App\Traits\Models\Orderable;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Spatie\Sitemap\Contracts\Sitemapable;
|
||||
use Spatie\Sitemap\Tags\Url;
|
||||
use Uwil\Laravel\Redirections\Interfaces\RedirectableInterface;
|
||||
use Uwil\Laravel\Redirections\Traits\IsRedirectable;
|
||||
use Uwil\Seo\Laravel\Interfaces\SeoInterface;
|
||||
use Uwil\Seo\Laravel\Objects\SeoItem;
|
||||
use Uwil\Seo\Laravel\Traits\SeoTrait;
|
||||
use Uwil\SitemapGenerator\Lib\SitemapHelper;
|
||||
use Kwaadpepper\Enum\Traits\CastsEnums;
|
||||
|
||||
/**
|
||||
* @property integer $id Id.
|
||||
* @property string $title Title.
|
||||
* @property string $slug Slug of the title.
|
||||
* @property string $seo_title SEO Title.
|
||||
* @property string $seo_description SEO description.
|
||||
* @property \App\Enums\Advices\AdviceTypeEnum $type Type of the advice.
|
||||
* @property string $picture Path of a picture.
|
||||
* @property string $picture_alt Picture's attribute alt.
|
||||
* @property string $picture_title Picture's attribute title.
|
||||
* @property string $sticker Path of a sticker.
|
||||
* @property string $sticker_alt Sticker's attribute alt.
|
||||
* @property string $sticker_title Sticker's attribute title.
|
||||
* @property string $sticker_sm Path of a small sticker.
|
||||
* @property string $sticker_sm_alt small sticker's attribute alt.
|
||||
* @property string $sticker_sm_title Small sticker's attribute title.
|
||||
* @property string $preparation Preparation tips.
|
||||
* @property string|null $advice Advice.
|
||||
* @property array<array<string,string|integer>> $ingredients Ingredients.
|
||||
* @property integer|null $guests_nb Number of guests.
|
||||
* @property string|null $youtube_title Youtube title.
|
||||
* @property string|null $youtube_video_id Youtube video id.
|
||||
* @property integer|null $cooking_time Time of cooking.
|
||||
* @property integer|null $preparation_time Time of preparation.
|
||||
* @property \App\Enums\Advices\AdviceDifficultyEnum|null $difficulty Difficulty.
|
||||
* @property boolean $published Status.
|
||||
* @property integer $priority_order Priority Order.
|
||||
* @property-read \Illuminate\Support\Carbon $created_at Created date.
|
||||
* @property-read \Illuminate\Support\Carbon $updated_at Updated date.
|
||||
*
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<\App\Models\Advice> $recipes
|
||||
* HasMany Recipes.
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<\App\Models\Advice> $tips
|
||||
* HasMany Tips.
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<\App\Models\Advice> $advices
|
||||
* Advices Belongs-To-Many relationship.
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<\App\Models\Product> $products
|
||||
* Products Belongs-To-Many relationship.
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<\App\Models\Tag> $tags
|
||||
* Tags Morph-To-Many relationship.
|
||||
*/
|
||||
class Advice extends Authenticatable implements SeoInterface, Sitemapable, RedirectableInterface, OrderableInterface
|
||||
class Advice extends Authenticatable
|
||||
{
|
||||
use CastsEnums;
|
||||
use HasFactory;
|
||||
use SeoTrait;
|
||||
use IsRedirectable;
|
||||
use Orderable;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
|
|
@ -99,20 +48,27 @@ class Advice extends Authenticatable implements SeoInterface, Sitemapable, Redir
|
|||
'cooking_time',
|
||||
'preparation_time',
|
||||
'difficulty',
|
||||
'published',
|
||||
'priority_order'
|
||||
'status'
|
||||
];
|
||||
|
||||
/**
|
||||
* Map attribute names to enum classes.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $enumCasts = [
|
||||
'type' => AdviceTypeEnum::class,
|
||||
'difficulty' => AdviceDifficultyEnum::class
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
*
|
||||
* @var array<string,string>
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'ingredients' => 'array',
|
||||
'published' => 'bool',
|
||||
'type' => AdviceTypeEnum::class,
|
||||
'difficulty' => AdviceDifficultyEnum::class,
|
||||
'status' => 'bool'
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
@ -120,11 +76,10 @@ class Advice extends Authenticatable implements SeoInterface, Sitemapable, Redir
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
protected static function booted(): void
|
||||
protected static function booted()
|
||||
{
|
||||
static::creating(function (self $model) {
|
||||
self::manageFields($model);
|
||||
self::bootOrderable();
|
||||
});
|
||||
static::updating(function (self $model) {
|
||||
self::manageFields($model);
|
||||
|
|
@ -139,19 +94,18 @@ class Advice extends Authenticatable implements SeoInterface, Sitemapable, Redir
|
|||
FileStorageHelper::removeFile($model, 'picture');
|
||||
FileStorageHelper::removeFile($model, 'sticker');
|
||||
FileStorageHelper::removeFile($model, 'sticker_sm');
|
||||
self::setOrder($model);
|
||||
});
|
||||
}
|
||||
|
||||
// * METHODS
|
||||
|
||||
/**
|
||||
* Common methods function.
|
||||
* Manage fields on this model event.
|
||||
*
|
||||
* @param self $model
|
||||
* @param \Illuminate\Database\Eloquent\Model $model
|
||||
* @return void
|
||||
*/
|
||||
private static function manageFields(self $model): void
|
||||
private static function manageFields(Model $model)
|
||||
{
|
||||
self::assertTitleIsUnique($model->title, $model->id);
|
||||
$model->slug = Str::slug($model->title);
|
||||
|
|
@ -185,7 +139,7 @@ class Advice extends Authenticatable implements SeoInterface, Sitemapable, Redir
|
|||
* @return void
|
||||
* @throws \Illuminate\Validation\ValidationException Error exception.
|
||||
*/
|
||||
private static function assertLimitTags(int $nbTagsInBdd): void
|
||||
private static function assertLimitTags(int $nbTagsInBdd)
|
||||
{
|
||||
if ($nbTagsInBdd > 2) {
|
||||
throw ValidationException::withMessages([
|
||||
|
|
@ -201,7 +155,7 @@ class Advice extends Authenticatable implements SeoInterface, Sitemapable, Redir
|
|||
* @return void
|
||||
* @throws \Illuminate\Validation\ValidationException Error exception.
|
||||
*/
|
||||
private static function assertLimitAdvices(int $nbAdvicesInBdd): void
|
||||
private static function assertLimitAdvices(int $nbAdvicesInBdd)
|
||||
{
|
||||
if ($nbAdvicesInBdd > 6) {
|
||||
throw ValidationException::withMessages([
|
||||
|
|
@ -213,20 +167,20 @@ class Advice extends Authenticatable implements SeoInterface, Sitemapable, Redir
|
|||
/**
|
||||
* Limit products associated.
|
||||
*
|
||||
* @param self $model
|
||||
* @param \Illuminate\Database\Eloquent\Model $model
|
||||
* @return void
|
||||
* @throws \Illuminate\Validation\ValidationException Error exception.
|
||||
*/
|
||||
private static function assertLimitProducts(self $model): void
|
||||
private static function assertLimitProducts(Model $model)
|
||||
{
|
||||
$nbProductsInBdd = $model->products()->count();
|
||||
if ($model->type->value == AdviceTypeEnum::recipes->value()) {
|
||||
if ($model->type->value == AdviceTypeEnum::recipes()->value) {
|
||||
if ($nbProductsInBdd < 1 || $nbProductsInBdd > 3) {
|
||||
throw ValidationException::withMessages([
|
||||
'Vous devez associer 1 à 3 produits.'
|
||||
]);
|
||||
}
|
||||
} elseif ($model->type->value == AdviceTypeEnum::tips->value()) {
|
||||
} elseif ($model->type->value == AdviceTypeEnum::tips()->value) {
|
||||
if ($nbProductsInBdd > 3) {
|
||||
throw ValidationException::withMessages([
|
||||
'Vous devez associer au maximum 3 produits.'
|
||||
|
|
@ -238,12 +192,12 @@ class Advice extends Authenticatable implements SeoInterface, Sitemapable, Redir
|
|||
/**
|
||||
* Asserts using validation that the title is unique.
|
||||
*
|
||||
* @param self $model
|
||||
* @param \Illuminate\Database\Eloquent\Model $model
|
||||
* @return void
|
||||
*/
|
||||
private static function setCookingtimePreparationtimeValues(self $model): void
|
||||
private static function setCookingtimePreparationtimeValues(Model $model)
|
||||
{
|
||||
if ($model->type->value != AdviceTypeEnum::recipes->value()) {
|
||||
if ($model->type->value != AdviceTypeEnum::recipes()->value) {
|
||||
$model->cooking_time = null;
|
||||
$model->preparation_time = null;
|
||||
}
|
||||
|
|
@ -252,11 +206,11 @@ class Advice extends Authenticatable implements SeoInterface, Sitemapable, Redir
|
|||
/**
|
||||
* Asserts using validation that the title is unique.
|
||||
*
|
||||
* @param string $title
|
||||
* @param mixed $title
|
||||
* @param integer|null $id
|
||||
* @return void
|
||||
*/
|
||||
private static function assertTitleIsUnique(string $title, ?int $id = null): void
|
||||
private static function assertTitleIsUnique($title, ?int $id = null)
|
||||
{
|
||||
$table = (new self())->getTable();
|
||||
ToolboxHelper::assertFieldIsUnique($table, 'title', $title, $id);
|
||||
|
|
@ -268,21 +222,9 @@ class Advice extends Authenticatable implements SeoInterface, Sitemapable, Redir
|
|||
*
|
||||
* @return \Illuminate\Database\Eloquent\Collection<\App\Models\Advice>
|
||||
*/
|
||||
public function recipesQuery(): \Illuminate\Database\Eloquent\Collection
|
||||
public function recipes(): Collection
|
||||
{
|
||||
return $this->advices()->where('type', AdviceTypeEnum::recipes)->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the advice recipes
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Casts\Attribute
|
||||
*/
|
||||
protected function recipes(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
get: fn() => $this->recipesQuery(),
|
||||
);
|
||||
return $this->advices()->where('type', AdviceTypeEnum::recipes())->get();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -290,107 +232,40 @@ class Advice extends Authenticatable implements SeoInterface, Sitemapable, Redir
|
|||
*
|
||||
* @return \Illuminate\Database\Eloquent\Collection<\App\Models\Advice>
|
||||
*/
|
||||
public function tipsQuery(): \Illuminate\Database\Eloquent\Collection
|
||||
public function tips(): Collection
|
||||
{
|
||||
return $this->advices()->where('type', AdviceTypeEnum::tips)->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the advice tips
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Casts\Attribute
|
||||
*/
|
||||
protected function tips(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
get: fn() => $this->tipsQuery(),
|
||||
);
|
||||
}
|
||||
|
||||
// * REDIRECTIONS.
|
||||
|
||||
/**
|
||||
* Get the front url of this model.
|
||||
* Should return the model.show route, with all binded elements if needed.
|
||||
*
|
||||
* @param string $modelKey
|
||||
* @return string
|
||||
*/
|
||||
public function getFrontUrl(string $modelKey): string
|
||||
{
|
||||
return route('fo.tips.show', $modelKey);
|
||||
return $this->advices()->where('type', AdviceTypeEnum::tips())->get();
|
||||
}
|
||||
|
||||
// * RELATIONSHIPS
|
||||
|
||||
/**
|
||||
* Advices Belongs-To-Many relationship.
|
||||
* BelongsToMany advices
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
*/
|
||||
public function advices(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
public function advices()
|
||||
{
|
||||
return $this->belongsToMany(Advice::class, 'advice_advice', 'advice_id', 'advice_related_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Products Belongs-To-Many relationship.
|
||||
* BelongsToMany products
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
*/
|
||||
public function products(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
public function products()
|
||||
{
|
||||
return $this->belongsToMany(Product::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tags Morph-To-Many relationship.
|
||||
* MorphToMany Tags
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\MorphToMany
|
||||
*/
|
||||
public function tags(): \Illuminate\Database\Eloquent\Relations\MorphToMany
|
||||
public function tags()
|
||||
{
|
||||
return $this->morphToMany(Tag::class, 'taggable');
|
||||
}
|
||||
|
||||
/**
|
||||
* Transfotrm to seoModel
|
||||
*
|
||||
* @return \Uwil\Seo\Laravel\Objects\SeoItem
|
||||
*/
|
||||
public function toSeoItem(): SeoItem
|
||||
{
|
||||
return new SeoItem(
|
||||
\trans($this->getTable()),
|
||||
$this->seo_title,
|
||||
$this->seo_description,
|
||||
$this->published ?? false,
|
||||
\route(\config('seo.bo_route_prefix') . $this->getTable() . '.edit', $this),
|
||||
$this->type === AdviceTypeEnum::recipes ? route('fo.recipes.show', $this) : route('fo.tips.show', $this)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* toSitemapTag method
|
||||
*
|
||||
* @return Url|string|array
|
||||
*/
|
||||
public function toSitemapTag(): Url | string | array
|
||||
{
|
||||
$model = $this;
|
||||
$route = $this->type === AdviceTypeEnum::tips ? 'fo.tips.show' : 'fo.recipes.show';
|
||||
$params = ['publishedAdvice' => $model];
|
||||
return SitemapHelper::generateUrl($route, $params, $model);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Group ordering by type.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getOrderGroupField(): string
|
||||
{
|
||||
return 'type';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,124 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Lib\Helpers\FileStorageHelper;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Uwil\Laravel\Common\Helpers\ToolboxHelper;
|
||||
|
||||
class BrigadeSection extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'title',
|
||||
'content',
|
||||
'picture',
|
||||
'picture_alt',
|
||||
'picture_title',
|
||||
'button_display',
|
||||
'button_text',
|
||||
'button_url',
|
||||
'button_newtab',
|
||||
'published',
|
||||
'order'
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
*
|
||||
* @var array<string,string>
|
||||
*/
|
||||
protected $casts = [
|
||||
'button_display' => 'bool',
|
||||
'button_newtab' => 'bool',
|
||||
'published' => 'bool',
|
||||
];
|
||||
|
||||
/**
|
||||
* Perform any actions required after the model boots.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::creating(function (self $model) {
|
||||
self::setOrder($model);
|
||||
self::manageFields($model);
|
||||
});
|
||||
static::updating(function (self $model) {
|
||||
self::manageFields($model);
|
||||
});
|
||||
static::updated(function (self $model) {
|
||||
FileStorageHelper::removeOldFile($model, 'picture');
|
||||
});
|
||||
static::updating(function (self $model) {
|
||||
self::manageFields($model);
|
||||
});
|
||||
static::deleting(function (self $model) {
|
||||
self::assertLimitPublishedSections($model, true);
|
||||
});
|
||||
static::deleted(function (self $model) {
|
||||
FileStorageHelper::removeFile($model, 'picture');
|
||||
});
|
||||
}
|
||||
|
||||
// * METHODS
|
||||
|
||||
/**
|
||||
* Common methods function.
|
||||
*
|
||||
* @param self $model
|
||||
* @return void
|
||||
*/
|
||||
private static function manageFields(self $model): void
|
||||
{
|
||||
self::assertLimitPublishedSections($model);
|
||||
|
||||
ToolboxHelper::assertNoInternalBoUrls('content', $model->content);
|
||||
ToolboxHelper::assertNoInternalBoUrls('button_url', $model->content);
|
||||
|
||||
$model->content = clean($model->content);
|
||||
$model->picture = FileStorageHelper::storeFile($model, $model->picture);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the limit of published element is reached.
|
||||
*
|
||||
* @param self $model
|
||||
* @param boolean $isDeletion
|
||||
* @return void
|
||||
* @throws \Illuminate\Validation\ValidationException Returns if fails.
|
||||
*/
|
||||
private static function assertLimitPublishedSections(self $model, bool $isDeletion = false)
|
||||
{
|
||||
$count = self::query()->where('published', true)->count();
|
||||
if (
|
||||
(!$model->published && $count <= 1) ||
|
||||
($model->published && $count >= 5) ||
|
||||
($isDeletion && $count === 1)
|
||||
) {
|
||||
throw ValidationException::withMessages([
|
||||
'Il doit y avoir entre 1 et 5 sections publiées simultanément.'
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -9,28 +9,17 @@ use App\Lib\Helpers\ToolboxHelper;
|
|||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Kwaadpepper\Enum\Traits\CastsEnums;
|
||||
|
||||
/**
|
||||
* @property integer $id Id.
|
||||
* @property \App\Enums\ExpertiseProducts\ExpertiseProductPageEnum $page Title.
|
||||
* @property string $label Label of the title.
|
||||
* @property string $title Title.
|
||||
* @property string $subtitle Subtitle.
|
||||
* @property array $points Type of the advice.
|
||||
* @property boolean $is_frenchpoultry Is frenchpoultry or not.
|
||||
* @property boolean $is_natureeleveurs Is natureeleveurs or not.
|
||||
* @property \App\Enums\NutriscoreEnum $nutriscore Nutriscore.
|
||||
* @property-read \Illuminate\Support\Carbon $created_at Created date.
|
||||
* @property-read \Illuminate\Support\Carbon $updated_at Updated date.
|
||||
*/
|
||||
class ExpertiseProduct extends Model
|
||||
{
|
||||
use CastsEnums;
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array<int, string>
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'page',
|
||||
|
|
@ -40,20 +29,28 @@ class ExpertiseProduct extends Model
|
|||
'points',
|
||||
'is_frenchpoultry',
|
||||
'is_natureeleveurs',
|
||||
'nutriscore',
|
||||
'nutriscore'
|
||||
];
|
||||
|
||||
/**
|
||||
* Map attribute names to enum classes.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $enumCasts = [
|
||||
'page' => ExpertiseProductPageEnum::class,
|
||||
'nutriscore' => NutriscoreEnum::class
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
*
|
||||
* @var array<string,string>
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'points' => 'array',
|
||||
'is_frenchpoultry' => 'bool',
|
||||
'is_natureeleveurs' => 'bool',
|
||||
'page' => ExpertiseProductPageEnum::class,
|
||||
'nutriscore' => NutriscoreEnum::class
|
||||
'points' => 'array',
|
||||
'is_frenchpoultry' => 'bool',
|
||||
'is_natureeleveurs' => 'bool'
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
@ -61,7 +58,7 @@ class ExpertiseProduct extends Model
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
protected static function booted(): void
|
||||
protected static function booted()
|
||||
{
|
||||
static::creating(function (self $model) {
|
||||
self::manageFields($model);
|
||||
|
|
@ -82,27 +79,28 @@ class ExpertiseProduct extends Model
|
|||
// * METHODS
|
||||
|
||||
/**
|
||||
* Common methods function.
|
||||
* Undocumented function
|
||||
*
|
||||
* @param self $model
|
||||
* @param Model $model
|
||||
* @return void
|
||||
*/
|
||||
private static function manageFields(self $model): void
|
||||
private static function manageFields(Model $model)
|
||||
{
|
||||
self::assertFieldIsUnique('label', $model->label, $model->id);
|
||||
self::assertFieldIsUnique('title', $model->title, $model->id);
|
||||
static::assertFieldIsUnique('label', $model->label, $model->id);
|
||||
static::assertFieldIsUnique('title', $model->title, $model->id);
|
||||
|
||||
self::assertNumberOfProductsVip($model->page->value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts using validation that the label is unique.
|
||||
* Asserts using validation that the label is unique
|
||||
*
|
||||
* @param string $name
|
||||
* @param mixed $field
|
||||
* @param integer|null $id
|
||||
* @return void
|
||||
*/
|
||||
private static function assertFieldIsUnique(string $name, mixed $field, ?int $id = null): void
|
||||
private static function assertFieldIsUnique(string $name, $field, ?int $id = null)
|
||||
{
|
||||
$table = (new self())->getTable();
|
||||
ToolboxHelper::assertFieldIsUnique($table, $name, $field, $id);
|
||||
|
|
@ -115,7 +113,7 @@ class ExpertiseProduct extends Model
|
|||
* @return void
|
||||
* @throws \Illuminate\Validation\ValidationException If there are more than 3 products.
|
||||
*/
|
||||
private static function assertNumberOfProductsVip(int $specie): void
|
||||
private static function assertNumberOfProductsVip(int $specie)
|
||||
{
|
||||
if (count(self::where('page', '=', $specie)->get()) >= 3) {
|
||||
throw ValidationException::withMessages([
|
||||
|
|
|
|||
|
|
@ -2,67 +2,25 @@
|
|||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Spatie\Sitemap\Tags\Url;
|
||||
use Spatie\CalendarLinks\Link;
|
||||
use App\Lib\Helpers\ToolboxHelper;
|
||||
use Uwil\Seo\Laravel\Objects\SeoItem;
|
||||
use Uwil\Seo\Laravel\Traits\SeoTrait;
|
||||
use App\Lib\Helpers\FileStorageHelper;
|
||||
use Spatie\Sitemap\Contracts\Sitemapable;
|
||||
use Uwil\SitemapGenerator\Lib\SitemapHelper;
|
||||
use Uwil\Seo\Laravel\Interfaces\SeoInterface;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Uwil\Laravel\Redirections\Traits\IsRedirectable;
|
||||
use App\Lib\Helpers\ToolboxHelper;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Uwil\Laravel\Redirections\Interfaces\RedirectableInterface;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
/**
|
||||
* @property-read string $reading_time Time reading of a news' page
|
||||
*/
|
||||
/**
|
||||
* @property integer $id Id.
|
||||
* @property string $title Title.
|
||||
* @property string $subtitle Type of the advice.
|
||||
* @property string $slug Slug of the title.
|
||||
* @property string $seo_title SEO Title.
|
||||
* @property string $seo_description SEO description.
|
||||
* @property string $picture Path of a picture.
|
||||
* @property string $picture_alt Picture's attribute alt.
|
||||
* @property string $picture_title Picture's attribute title.
|
||||
* @property string|null $picture2 Path of a second picture.
|
||||
* @property string|null $picture2_alt Second picture's attribute alt.
|
||||
* @property string|null $picture2_title Second picture's attribute title.
|
||||
* @property string $content First WYSWYG content.
|
||||
* @property string|null $content2 Second WYSWYG content.
|
||||
* @property \Illuminate\Support\Carbon|null $event_start Start of the event.
|
||||
* @property \Illuminate\Support\Carbon|null $event_end End of the event.
|
||||
* @property string|null $event_text Text of the event.
|
||||
* @property boolean $published Status.
|
||||
* @property-read string $reading_time Time reading of a news' page
|
||||
* @property-read \Illuminate\Support\Carbon $created_at Created date.
|
||||
* @property-read \Illuminate\Support\Carbon $updated_at Updated date.
|
||||
*
|
||||
* @property-read \Spatie\CalendarLinks\Link|null $cal_link
|
||||
*
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<\App\Models\News> $news
|
||||
* News Belongs-To-Many relationship.
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<\App\Models\Product> $products
|
||||
* Products Belongs-To-Many relationship.
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<\App\Models\Tags> $categories
|
||||
* Categories Morph-To-Many relationship.
|
||||
*/
|
||||
class News extends Authenticatable implements SeoInterface, Sitemapable, RedirectableInterface
|
||||
class News extends Authenticatable
|
||||
{
|
||||
use HasFactory;
|
||||
use SeoTrait;
|
||||
use IsRedirectable;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array<int,string>
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'title',
|
||||
|
|
@ -81,18 +39,18 @@ class News extends Authenticatable implements SeoInterface, Sitemapable, Redirec
|
|||
'event_start',
|
||||
'event_end',
|
||||
'event_text',
|
||||
'published',
|
||||
'status'
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
*
|
||||
* @var array<string,string>
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'event_start' => 'datetime',
|
||||
'event_end' => 'datetime',
|
||||
'published' => 'bool',
|
||||
'event_end' => 'datetime',
|
||||
'status' => 'bool'
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
@ -100,7 +58,7 @@ class News extends Authenticatable implements SeoInterface, Sitemapable, Redirec
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
protected static function booted(): void
|
||||
protected static function booted()
|
||||
{
|
||||
static::creating(function (self $model) {
|
||||
self::manageFields($model);
|
||||
|
|
@ -121,36 +79,15 @@ class News extends Authenticatable implements SeoInterface, Sitemapable, Redirec
|
|||
});
|
||||
}
|
||||
|
||||
// * ATTRIBUTES
|
||||
|
||||
/**
|
||||
* Get cal_link attribute
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Casts\Attribute
|
||||
*/
|
||||
public function calLink(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
get: fn() => (
|
||||
$this->exists() and
|
||||
($this->event_start && $this->event_end && $this->event_text)
|
||||
) ? Link::create(
|
||||
$this->title,
|
||||
$this->event_start,
|
||||
$this->event_end
|
||||
)->description($this->event_text)->ics() : null
|
||||
);
|
||||
}
|
||||
|
||||
// * METHODS
|
||||
|
||||
/**
|
||||
* Common methods function.
|
||||
* Manage fields on this model event.
|
||||
*
|
||||
* @param self $model
|
||||
* @param \Illuminate\Database\Eloquent\Model $model
|
||||
* @return void
|
||||
*/
|
||||
private static function manageFields(self $model): void
|
||||
private static function manageFields(Model $model)
|
||||
{
|
||||
self::assertTitleIsUnique($model->title, $model->id);
|
||||
$model->slug = Str::slug($model->title);
|
||||
|
|
@ -167,12 +104,11 @@ class News extends Authenticatable implements SeoInterface, Sitemapable, Redirec
|
|||
|
||||
/**
|
||||
* Limit products associated.
|
||||
*
|
||||
* @param integer $nbProductsInBdd
|
||||
* @return void
|
||||
* @throws \Illuminate\Validation\ValidationException Error exception.
|
||||
*/
|
||||
private static function assertLimitProducts(int $nbProductsInBdd): void
|
||||
private static function assertLimitProducts(int $nbProductsInBdd)
|
||||
{
|
||||
if ($nbProductsInBdd > 3) {
|
||||
throw ValidationException::withMessages([
|
||||
|
|
@ -183,12 +119,11 @@ class News extends Authenticatable implements SeoInterface, Sitemapable, Redirec
|
|||
|
||||
/**
|
||||
* Limit news associated.
|
||||
*
|
||||
* @param integer $nbNewsInBdd
|
||||
* @return void
|
||||
* @throws \Illuminate\Validation\ValidationException Error exception.
|
||||
*/
|
||||
private static function assertLimitNews(int $nbNewsInBdd): void
|
||||
private static function assertLimitNews(int $nbNewsInBdd)
|
||||
{
|
||||
if ($nbNewsInBdd > 3) {
|
||||
throw ValidationException::withMessages([
|
||||
|
|
@ -199,12 +134,11 @@ class News extends Authenticatable implements SeoInterface, Sitemapable, Redirec
|
|||
|
||||
/**
|
||||
* Limit news categories associated.
|
||||
*
|
||||
* @param integer $nbNewsCategoriesInBdd
|
||||
* @return void
|
||||
* @throws \Illuminate\Validation\ValidationException Error exception.
|
||||
*/
|
||||
private static function assertLimitNewsCategory(int $nbNewsCategoriesInBdd): void
|
||||
private static function assertLimitNewsCategory(int $nbNewsCategoriesInBdd)
|
||||
{
|
||||
if ($nbNewsCategoriesInBdd < 1 or $nbNewsCategoriesInBdd > 2) {
|
||||
throw ValidationException::withMessages([
|
||||
|
|
@ -216,11 +150,11 @@ class News extends Authenticatable implements SeoInterface, Sitemapable, Redirec
|
|||
/**
|
||||
* Asserts using validation that the title is unique.
|
||||
*
|
||||
* @param string $title
|
||||
* @param mixed $title
|
||||
* @param integer|null $id
|
||||
* @return void
|
||||
*/
|
||||
private static function assertTitleIsUnique(string $title, ?int $id = null): void
|
||||
private static function assertTitleIsUnique($title, ?int $id = null)
|
||||
{
|
||||
$table = (new self())->getTable();
|
||||
ToolboxHelper::assertFieldIsUnique($table, 'title', $title, $id);
|
||||
|
|
@ -231,9 +165,11 @@ class News extends Authenticatable implements SeoInterface, Sitemapable, Redirec
|
|||
/**
|
||||
* Getter reading_time.
|
||||
*
|
||||
* * USED
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getReadingTime(): string
|
||||
public function getReadingTime()
|
||||
{
|
||||
$allWords = count(explode(
|
||||
" ",
|
||||
|
|
@ -249,81 +185,35 @@ class News extends Authenticatable implements SeoInterface, Sitemapable, Redirec
|
|||
return ($time < 1) ? round(($allWords / 140) * 60, 0) . " seconde(s)" : $time . " minute(s)";
|
||||
}
|
||||
|
||||
// * REDIRECTIONS.
|
||||
|
||||
/**
|
||||
* Get the front url of this model.
|
||||
* Should return the model.show route, with all binded elements if needed.
|
||||
*
|
||||
* @param string $modelKey
|
||||
* @return string
|
||||
*/
|
||||
public function getFrontUrl(string $modelKey): string
|
||||
{
|
||||
return route('fo.news.show', $modelKey);
|
||||
}
|
||||
|
||||
// * RELATIONSHIPS
|
||||
|
||||
/**
|
||||
* News Morph-To-Many relationship.
|
||||
* BelongsToMany news
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
* @phpcs:disable Generic.NamingConventions.ConstructorName.OldStyle
|
||||
*/
|
||||
public function news(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
public function news()
|
||||
{
|
||||
// phpcs:enable
|
||||
return $this->belongsToMany(News::class, 'news_news', 'news_id', 'news_related_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Products Morph-To-Many relationship.
|
||||
* BelongsToMany products
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
*/
|
||||
public function products(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
public function products()
|
||||
{
|
||||
return $this->belongsToMany(Product::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Categories Morph-To-Many relationship.
|
||||
* BelongsToMany categories
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
*/
|
||||
public function categories(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
public function categories()
|
||||
{
|
||||
return $this->belongsToMany(NewsCategory::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* toSitemapTag method
|
||||
*
|
||||
* @return Url|string|array
|
||||
*/
|
||||
public function toSitemapTag(): Url | string | array
|
||||
{
|
||||
$model = $this;
|
||||
$route = 'fo.news.show';
|
||||
$params = ['actu' => $model];
|
||||
return SitemapHelper::generateUrl($route, $params, $model);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform to seoModel
|
||||
*
|
||||
* @return \Uwil\Seo\Laravel\Objects\SeoItem
|
||||
*/
|
||||
public function toSeoItem(): SeoItem
|
||||
{
|
||||
return new SeoItem(
|
||||
\trans($this->getTable()),
|
||||
$this->seo_title,
|
||||
$this->seo_description,
|
||||
$this->published ?? false,
|
||||
\route(\config('seo.bo_route_prefix') . $this->getTable() . '.edit', $this),
|
||||
route('fo.news.show', $this)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue