churakovmike/laravel-form-typecast

Laravel request form type casting

dev-master 2020-04-12 16:52 UTC

This package is auto-updated.

Last update: 2022-06-12 22:18:09 UTC


README

Requirements

  • laravel 5.5+

Getting started

Install

The package is available on packagist.

composer require churakovmike/laravel-form-typecast

Usage

You just need to use this trait.

<?php

namespace App\Http\Requests;

use ChurakovMike\FormTypeCast\TypeCastTrait;
use Illuminate\Foundation\Http\FormRequest;

class ExampleFormRequest extends FormRequest
{
    use TypeCastTrait;
    
    /**
    * @var array 
     */
    protected $casts = [
        'name' => 'string',
        'age' => 'int',
        'salary' => 'float',
    ];

}

This trait is a wrapper over HasAttributes.php trait.