churakovmike/laravel-form-typecast

Laravel request form type casting

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

This package is auto-updated.

Last update: 2024-11-13 03:35:24 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.