0
class MyFormRequest extends FormRequest
{
    public function __construct()
    {
        parent::__construct();
      
       here Request::all() returns empty array
    }

protected function prepareForValidation()
    {

here Request::all() returns array with my input

I need to get input in __construct. Google did not help me.

Pls, help me. How can I get input in __construct()?

I use Laravel 7.

7
  • the form request is actually filled (initialized) after it is created when resolved from the container Commented Nov 17, 2020 at 11:08
  • I understand it. But must be way to get input in constructor. I can use _GET or _POST. But I think it's not a good idea. Commented Nov 17, 2020 at 11:27
  • what are you doing in the constructor that you need that data? Commented Nov 17, 2020 at 11:28
  • I get Model object (document). Other methods: authorize(), prepareForValidation(), rules() use it. I can get object from route. ``` $this->doc = Route::input('doc'); ``` But now I need to get document by input params. Commented Nov 17, 2020 at 12:11
  • _POST is empty in __construct() :( Commented Nov 17, 2020 at 12:15

1 Answer 1

1

Does this help?

public function __construct(Request $request)
{
    dd($request->all());
}

Or have you tried the helper function request()->all()

I have tried both in a construct method of my controllers and works fine

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.