1. Go to this page and download the library: Download sylarele/laravel-set library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
sylarele / laravel-set example snippets
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');
/* [...] */
}
};
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);
}
/* [...] */
}
use Sylarele\LaravelSet\Service\ScheduleHandler;
->withSchedule(
(new ScheduleHandler([
dirname(__DIR__).'/app/Schedule/Command/*.php',
dirname(__DIR__).'/app/Schedule/Job/*.php',
]))
->handle(...)
)
php artisan schedule:list
enum PublicFileType: string
{
case FooImage = 'foo:image';
}
// config/image_rules.php
use Sylarele\LaravelSet\Media\Dto\Config\ImageConfigDto;
return [
'rules' => [
PublicFileType::FooImage->value => new ImageConfigDto(
resizeHeight: 300,
resizeWidth: 300,
),
],
];
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');
}
use Sylarele\LaravelSet\Media\Rule\FileRule;
public function rules(): array
{
return [
'image' => ['nullable', new FileRule(PublicFileType::FooImage)],
];
}
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',
],
],
];
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();
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.