End of Life
The functionality provided by this is now baked directly into Laravel 5.5+ thanks the Joseph Silber. You should use that 👍, (*1)
A trait you can utilise in your Laravel form request objects to ensure the data you are accessing from the request has been validated., (*2)
Why? See my post: Enforcing Valid Data Access From a Form Request Object., (*3)
Installation
You can install using composer from Packagist., (*4)
composer require timacdonald/laravel-access-validated-inputs
Versioning
This package uses Semantic Versioning. You can find out more about what this is and why it matters by reading the spec or for something more readable, check out this post., (*5)
Usage
First you need to use
the trait in your form request object:, (*6)
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use TiMacDonald\Http\Request\AccessesValidatedInputs;
class PostFormRequest extends FormRequest
{
use AccessesValidatedInputs;
//
}
Then in your controller you may call:, (*7)
<?php
namespace App\Http\Controllers;
use App\Post;
use App\Http\Requests\PostFormRequest;
class PostController extends Controller
{
public function store(PostFormRequest $form)
{
Post::create($form->validatedInputs());
//
}
}
Contributing
Please feel free to suggest new ideas or send through pull requests to make this better. If you'd like to discuss the project, feel free to reach out on Twitter., (*8)
What next?
I've been thinking this could be awesome if it actually removed all the unvalidated inputs automatically so that all the Request's native methods only
, intersect
etc return validated inputs., (*9)
License
This package is under the MIT License. See LICENSE file for details., (*10)