0

This issue was fixed in Laravel 5.4.9.

The two new middleware classes doesn't apply to my own Requests. The two new middleware are:

\App\Http\Middleware\TrimStrings::class
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class

However, they don't apply their changes to my own requests. Forexample: I have this request:

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Auth;

class CreateStoreRequest extends FormRequest
{
    public function authorize()
    {
        return Auth::check();
    }

    public function rules()
    {
        var_dump( $this->all() ); // Content not handled by middleware

        return [
            // Rules
        ];
    }
}

When i use var_dump, I can see that the content isn't changed.

If i use Illuminate\Http\Request in my controller it works.

Is there any way to implement the changes in my own request classes?

andershagbard
  • 1,116
  • 2
  • 14
  • 38
  • when you use CreateStoreRequest in your method, try to dd($request->all()) and share the result , it should work correctly – Achraf Khouadja Jan 29 '17 at 12:48
  • Returns unhandled content. I've also debugged the functions, and they are running. If i use the the helper request('field'), it return handled content. The issue is I want to use the handled content in my own request class for validation. – andershagbard Jan 29 '17 at 13:00
  • trim and convert it manually (use trim() and terany operators to convert) i think that those middlewares works after the request – Achraf Khouadja Jan 29 '17 at 13:45
  • They dont. They work in Illuminate\Http\Request, but not in my own request. This is definitely not intended. – andershagbard Jan 29 '17 at 14:08
  • Same problem here, cant find a way to apply TrimStrings and ConvertEmptyStringsToNull to my FormRequest. – Paul Vidal Feb 02 '17 at 19:26
  • @PaulVidal, I've added my solution. – andershagbard Feb 03 '17 at 10:22

1 Answers1

1

I found a solution in the Github rep.

Add the following to your request class.

public function all()
{
    $this->merge( $this->request->all() );

    return parent::all();
}

If you are checking for types in your rules, you might want to add "nullable" to the rules.

andershagbard
  • 1,116
  • 2
  • 14
  • 38