sylarele / laravel-set
Set of interfaces, objects, and practices to standardise Laravel backends
Installs: 273
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 6
pkg:composer/sylarele/laravel-set
Requires
- php: >=8.3
- laravel/framework: ^10.0|^11.0|^12.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.88
- orchestra/testbench: ^10.7
- orchestra/testbench-core: ^10.8
- phpstan/phpstan: ^2.1
- phpstan/phpstan-strict-rules: ^2.0
- phpunit/phpunit: ^12.4
- rector/rector: ^2.1
- shipmonk/composer-dependency-analyser: ^1.8
- dev-master
- v0.3.1
- v0.3.0
- v0.2.2
- v0.2.1
- v0.2.0
- v0.1.0
- v0.0.1
- dev-hotfix/file-rule-service-nullable
- dev-feat/file-rules
- dev-dependabot/github_actions/master/actions/checkout-6
- dev-dependabot/composer/master/illuminate/contracts-12.35.1
- dev-dependabot/composer/master/illuminate/http-12.35.1
- dev-dependabot/composer/master/rector/rector-2.2.6
- dev-dependabot/composer/master/illuminate/console-12.35.1
- dev-dependabot/composer/master/phpstan/phpstan-2.1.31
This package is auto-updated.
Last update: 2025-12-05 16:04:29 UTC
README
Set of interfaces, objects, and practices to standardise Laravel backends
Schedule list
Initialise your schedule directory
app/
└─ Schedule/
├─ Command/ # for $schedule->command
└─ Job/ # for $schedule->job
Add your commands and jobs. Then return an anonymous class that inherits from Sylarele\LaravelSet\Contract\Console\ScheduleInterface.
<?php declare(strict_types=1); use App\Console\Command\AcmeCommand; use Illuminate\Console\Scheduling\Schedule; use Sylarele\LaravelSet\Contract\Console\ScheduleInterface; return new class() implements ScheduleInterface { public function handle(Schedule $schedule): void { $schedule->command(AcmeCommand::class)->dailyAt('08:00'); /* [...] */ } };
Then declare your commands in the kernel
In Laravel 10
<?php namespace App\Console; use Illuminate\Console\Scheduling\Schedule; use Illuminate\Foundation\Console\Kernel as ConsoleKernel; use Sylarele\LaravelSet\Service\ScheduleHandler; class Kernel extends ConsoleKernel { protected function schedule(Schedule $schedule): void { $scheduleHandler = new ScheduleHandler([ base_path('app/Schedule/Command/*.php'), base_path('app/Schedule/Job/*.php'), ]); $scheduleHandler->handle($schedule); } /* [...] */ }
In Laravel >= 11
use Sylarele\LaravelSet\Service\ScheduleHandler; ->withSchedule( (new ScheduleHandler([ dirname(__DIR__).'/app/Schedule/Command/*.php', dirname(__DIR__).'/app/Schedule/Job/*.php', ])) ->handle(...) )
See the schedule list :
php artisan schedule:list
Media
Rules
When you need to manage multiple media types in your application, it is best to centralize the validation rules in your configuration.
Create an enumeration to list your files:
<?php enum PublicFileType: string { case FooImage = 'foo:image'; }
Create a file_rules.php and image_rules.php configuration file and declare your validation rules:
<?php // config/file_rules.php use Sylarele\LaravelSet\Media\Dto\Config\FileRuleConfigDto; return [ 'rules' => [ PublicFileType::FooImage->value => FileRuleConfigDto::fromImage(), ], ];
The rules available for your media are:
- FileRuleConfigDto::fromImage(),
{min: 1kb, max: 400kb, mimes: ['png', 'jpg', 'jpeg', 'webp']}
- FileRuleConfigDto::fromFile(),
{min: 1kb, max: 15mb, mimes: ['*']}
- FileRuleConfigDto::fromPdf(),
{min: 1kb, max: 15mb, mimes: ['pdf']}
- FileRuleConfigDto::fromDocument(),
{min: 1kb, max: 15mb, mimes: ['csv', 'doc', 'docx', 'pdf', 'png', 'jpg', 'jpeg', 'xls', 'xlsx', 'webp']}
You can also rewrite the rules according to your needs by filling in the input parameters.
<?php // config/image_rules.php use Sylarele\LaravelSet\Media\Dto\Config\ImageConfigDto; return [ 'rules' => [ PublicFileType::FooImage->value => new ImageConfigDto( resizeHeight: 300, resizeWidth: 300, ), ], ];
Declare your configurations in your provider:
<?php use Sylarele\LaravelSet\Media\Service\FileRuleService; public function register(): void { $this->app ->when(FileRuleService::class) ->needs('$fileRulesConfig') ->giveConfig('file_rules.rules'); $this->app ->when(FileRuleService::class) ->needs('$imagesConfig') ->giveConfig('image_rules.rules'); }
In your FormRequest, call your rule with the key from your file:
use Sylarele\LaravelSet\Media\Rule\FileRule; public function rules(): array { return [ 'image' => ['nullable', new FileRule(PublicFileType::FooImage)], ]; }
Modify the translation of the following rules to include the format:
return [ 'file_rules' => [ 'gt' => 'The :attribute field must be greater than :value :format.', 'lt' => 'The :attribute field must be less than :value :format.', 'unit' => [ 'kb' => 'Kb', 'mb' => 'Mb', 'gb' => 'Gb', ], ], ];
You can inform your fronts with an API endpoint using the service and resource provided by the package.
<?php declare(strict_types=1); namespace App\Http\Controllers; use App\Enums\File\PublicFileType; use Illuminate\Http\JsonResponse; use Sylarele\LaravelSet\Media\Http\Resource\FileRuleResource; use Sylarele\LaravelSet\Media\Service\FileRuleService; class FileRuleController { public function __construct( private readonly FileRuleService $fileRuleService ) { } public function index(): JsonResponse { $list = $this->fileRuleService->listByScope(PublicFileType::cases()); return FileRuleResource::collection($list)->response(); } }
The following example will return the following JSON:
{
"data": [
{
"name": "foo:image",
"file_rule": {
"type": "image",
"mimes": [
"png",
"jpg",
"jpeg",
"webp"
],
"size_min": {
"size": 1,
"unit": "kb",
"bytes": 1000
},
"size_max": {
"size": 400,
"unit": "kb",
"bytes": 400000
}
},
"image_config": {
"height": 100,
"width": 100
}
}
]
}