Laravel Request::all() Should Not Be Called Statically

前端 未结 9 1541
迷失自我
迷失自我 2020-11-28 20:53

In Laravel, I\'m trying to call $input = Request::all(); on a store() method in my controller, but I\'m getting the following error:

9条回答
  •  执笔经年
    2020-11-28 21:29

    Inject the request object into the controller using Laravel's magic injection and then access the function non-statically. Laravel will automatically inject concrete dependencies into autoloaded classes

    class MyController() 
    {
    
       protected $request;
    
       public function __construct(\Illuminate\Http\Request $request)
       {
           $this->request = $request;
       }
    
       public function myFunc()
       {
           $input = $this->request->all();
       }
    
    }
    

提交回复
热议问题