Updated the UpdateProductRequest and UpdateRecipeRequest to use built-in validation rules for file uploads, removing custom validation methods for pictures and PDFs. This change streamlines the validation process and improves code readability. refactor(helper): remove unused FileStorageHelper Deleted the FileStorageHelper class as it was no longer needed, simplifying the codebase. refactor(toolbox): clean up ToolboxHelper methods Removed unused methods and simplified existing ones in ToolboxHelper to enhance maintainability. feat(models): add translation search method to Product and Recipe Added a new method `whereTranslationLike` to both Product and Recipe models to facilitate searching translations. chore(config): add storage service prefix configuration Introduced a new configuration option for storage service prefix to allow customization of media paths. fix(validation): add file existence validation message Added a French translation for the file existence validation message to improve user feedback. feat(routes): add media route for file access Implemented a new route for accessing media files through a MediaController, enhancing file management capabilities.
62 lines
1.9 KiB
PHP
62 lines
1.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Lib\Helpers;
|
|
|
|
use Illuminate\Support\Facades\Validator;
|
|
use Illuminate\Support\Str;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class ToolboxHelper extends ToolboxHelperCore
|
|
{
|
|
/**
|
|
* Strip scheme (https) on oembed urls
|
|
* Only embed allowed are for MP4 self hosted videos right now
|
|
*
|
|
* https is force by ckeditor MediaElements which natively supports
|
|
* only cloud hosted medias (youtube, spotify etc..)
|
|
*/
|
|
public static function stripCkEditorSchemesOnMediaInputs(string $input): string
|
|
{
|
|
return Str::of($input)
|
|
->replaceMatches('/(?<=<oembed url=")(http:\/\/)(?=.*?">)/m', '')
|
|
->toString();
|
|
}
|
|
|
|
/**
|
|
* Asserts that the field is unique.
|
|
*
|
|
* @param array<mixed>|string|int|float|bool|null $value
|
|
*
|
|
* @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,
|
|
null | int | string $id = null,
|
|
\Closure | string | null $query = null
|
|
): void {
|
|
if (! $query) {
|
|
Validator::make([$field => $value], [
|
|
(string) str_replace('.', '\.', $field) => Rule::unique($table, $field)->ignore($id),
|
|
], [
|
|
(string) str_replace('.', '\.', "{$field}.unique") => trans(
|
|
'validation.unique',
|
|
['attribute' => $field]
|
|
),
|
|
])->validate();
|
|
|
|
return;
|
|
}
|
|
Validator::make([$field => $value], [
|
|
$field => Rule::unique($table)->where($query)->ignore($id),
|
|
], [
|
|
$field . '.unique' => trans(
|
|
'validation.unique',
|
|
['attribute' => $field]
|
|
),
|
|
])->validate();
|
|
}
|
|
}
|