For some reason I am unable to validate data

2020-05-27 php laravel controller

I am trying to validate my data but for some reason I am getting this error " Trying to get property 'title' of non-object"

Here's My Controller:-

public function store(Request $request)

  $data = request()->validate([
        'title' => 'required',
        'body' => 'required',



  return redirect('/home');



request()->validate([]); will return Array with validated data. You are using $data->title but $data is NOT an Object but Array.

Instead use

'title' => $data['title'],