Download the PHP package rickselby/laravel-request-field-types without Composer

On this page you can find all versions of the php package rickselby/laravel-request-field-types. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-request-field-types

Laravel Request Field Types

PHP 7.0+ Build Status SensioLabs Insight Code Coverage

A way of defining common input field types in a central location and use them among all requests in your app.

NB: 3.x passes tests but I haven't tried it 'for real' yet; I will do so at some point and may write better tests...

Laravel Request Field Types Laravel PHP
3.x 5.6+ 7.1.3+
2.x 5.4 – 5.5 7.0+

Installing

Under Laravel >=5.5, the service provider will be automatically registered.

Terminology

'Field' is used as two different terms here; I hope I've been clear throughout the documentation:

Defining field types

Each field must implement RickSelby\LaravelRequestFieldTypes\InterfacesFieldTypeInterface. RickSelby\LaravelRequestFieldTypes\BaseFieldType implements the interface and sets up common functions, and is a good starting place to implementing your own fields.

Two things need implementing from the BaseFieldType:

An example field is included (DateFieldType).

Using field types in requests

Start by extending RickSelby\LaravelRequestFieldTypes\FieldTypesRequest instead of Illuminate\Foundation\Http\FormRequest.

Then, two functions need defining:

There is no need to define rules() and messages(); these are managed within the class.

defineRules()

Instead of adding rules to an array in rules(), we can define them using functions here.

For a defined field types, use setInputsFor():

For other fields, rules can be set directly with setRules():

Ordering

The request keeps track of the order rules are set, and returns the rules in the given order, so the validation messages are returned in the desired order. It is possible to override the field order, if preferred:

defineMessages()

Custom messages for defined field types' default rules can be set in the field type. Other messages can be set for rules using setMessage()

Modifying the request data

(This is probably a contentious way of modifying input, but it makes sense to me...)

Say we have a date field. The input field knows what format will be generated, and the request will know what format to validate. Where does it get converted for use in the rest of the app? Do we need to define the date format elsewhere as well, or can this be handled in the request?

Since the request knows about the expected input formats, it seems the right place to modify (valid) data for use in the rest of the app.

The supplied DateFieldType does this; the mapAfterValidationFunction will be run on all input fields set for this field type once validation has suceeded but before the validation returns.

If you need to do more complex alterations to the request data, the modifyInputAfterValidation function can be overridden directly.

...but why?

This was mostly driven by the desire to modify the request data.

Starting with a date field - must I define the date format in every request? Can I have a single base request that others extend from, and I define it there? Can I convert the input to a carbon instance before it is returned to the app?

Then, other fields fell into the same pattern - other inputs that could be modified to a better format for use in the app. The base request for the app became large and unwieldy, and thus this class was born.

Perhaps it is overkill, even for defining common field types within an app.


All versions of laravel-request-field-types with dependencies

PHP Build Version
Package Version
Requires laravel/framework Version 10.*|11.*
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package rickselby/laravel-request-field-types contains the following files

Loading the files please wait ....