Laravel - must be of the type array, none given

后端 未结 1 1411
死守一世寂寞
死守一世寂寞 2021-01-26 16:23

Having a strange problem with my laravel 5.2 build, I\'m trying to send data from a form to my database and for some reason an error keeps being thrown on submit which states \"

相关标签:
1条回答
  • 2021-01-26 17:01

    No data is passed to the controller when you post to a route. Instead, you access the data through the Request object by injecting it into the method, or by using the Request:: or Input:: facades.

    protected function postStatus(Illuminate\Http\Request $request)
    {
    
        $data = $request->all();
    
        return Posts::create([
            'user_name' => $data['user_name'],
            'body' => $data['body'],
            'photo' => $data['photo'],
            'visibility' => $data['visibility'],
        ]);
    }
    
    0 讨论(0)
提交回复
热议问题