Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Easy Request Laravel Package

shureban/laravel-easy-request

Laravel package that adds typed getters to FormRequest via PHPDoc @method annotations. Call $request->name(), $request->age(), etc., and values are cast to bool/int/float/Carbon/DateTime. Supports camelCase methods with snake_case input keys.

View on GitHub
Deep Wiki
Context7

Laravel easy request

Installation

Require this package with composer using the following command:

composer require shureban/laravel-easy-request

Add the following class to the providers array in config/app.php:

Shureban\LaravelEasyRequest\EasyRequestServiceProvider::class,

You can also publish the config file to change implementations (ie. interface to specific class).

php artisan vendor:publish --provider="Shureban\LaravelEasyRequest\EasyRequestServiceProvider"

How to use

All what you need, that is type PhpDoc for your request class.

For example:

/**
 * @method string name()
 * @method boolean isConfirmed()
 * @method bool isAdult()
 * @method integer age()
 * @method int size()
 * @method float salary()
 * @method array workingDays()
 * @method mixed description()
 * @method additionalInformation()
 * @method string|null managerName()
 * @method DateTime birthday()
 * @method Carbon firstWorkingDay()
 */
class CustomRequest extends \Illuminate\Foundation\Http\FormRequest
{
}

class RegistrationController extends Controller
{
    public function __invoke(CustomRequest $request): JsonResponse
    {
        dd(
            $request->name(), // return value with string type
            $request->isConfirmed(), // return value with bool type
            $request->isAdult(), // return value with bool type
            $request->age(), // return value with integer type
            $request->size(), // return value with integer type
            $request->salary(), // return value with float type
            $request->workingDays(), // return array value
            $request->description(), // return original value
            $request->additionalInformation(), // return original value
            $request->managerName(), // return string value or NULL
            $request->birthday(), // return date with type DateTime
            $request->firstWorkingDay(), // return date as Carbon type
        );    
    }
}

That is not a problem if you methods written in camelCase format and your request data in snake_case. You may use any of cases to get your value.

For example:

/**
 * @method int userId()
 * @method int client_id()
 */
class CustomRequest extends \Illuminate\Foundation\Http\FormRequest
{
    public function rules(): array
    {
        return [
            'user_id' => ['required', 'int'],
            'clientId' => ['required', 'int'],
        ];
    }
}

class RegistrationController extends Controller
{
    public function __invoke(CustomRequest $request): JsonResponse
    {
        dd(
            $request->userId(), // return value for field user_id
            $request->client_id(), // return value for field clientId
        );    
    }
}

If you need to work with models, and get model by field_id, that is easy.

For example:

/**
 * @method User user()
 */
class CustomRequest extends \Illuminate\Foundation\Http\FormRequest
{
    public function rules(): array
    {
        return [
            'user_id' => ['required', 'int'],
        ];
    }
}

class RegistrationController extends Controller
{
    public function __invoke(CustomRequest $request): JsonResponse
    {
        dd(
            $request->user(), // return instance of models User
        );    
    }
}

You have to name your property with _id ending or Id(in camel case), and set method type which is extends Model.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor