PHP code example of kr0lik / laravel-param-converter

1. Go to this page and download the library: Download kr0lik/laravel-param-converter 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/ */

    

kr0lik / laravel-param-converter example snippets




declare(strict_types=1);

use Kr0lik\ParamConverter\Converter\RequestDataConverter;
use Kr0lik\ParamConverter\Converter\QueryParamConverter;

return [
    'request' => [
        'autoConvert' => true,
    ],
    'converters' => [
        RequestDataConverter::NAME => RequestDataConverter::class,
        QueryParamConverter::NAME => QueryParamConverter::class,
    ],
];



declare(strict_types=1);

use Kr0lik\ParamConverter\Contract\RequestDtoInterface;
use Symfony\Component\Validator\Constraints as Assert;

final readonly class TextDto implements RequestDtoInterface
{
    public function __construct(
        #[Assert\GreaterThanOrEqual(10)]
        public int               $a,
        #[Assert\NotBlank()]
        public string            $b,
        public DateTimeImmutable $c,
    ) {
    }
}


use Kr0lik\ParamConverter\Annotation\ParamConverter;

class YourAction extends Controller
{
    #[ParamConverter('token', converter: QueryParamConverter::NAME)]
    #[ParamConverter("requestDto", class=TextDto::class)]
    public function __invoke(string $token, TextDto $requestDto)
    {
        ....
    }
}


use Kr0lik\ParamConverter\Annotation\ParamConverter;

class YourAction extends Controller
{
    public function __invoke(TextDto $requestDto)
    {
        ....
    }
}

$ php artisan vendor:publish --provider="Kr0lik\ParamConverter\ParamConverterServiceProvider"