2
votes

ERROR

Symfony\Component\Debug\Exception\FatalThrowableError thrown with message "Call to a member function getClientOriginalExtension() on null"

Stacktrace:

0 Symfony\Component\Debug\Exception\FatalThrowableError in MYPATH\app\Http\Controllers\PostsController.php:66

Controller

public function store(Request $request)
  {
    
    $this->validate(request(),[

        'title' => 'required',

        'image' => 'image|mimes:jpeg,png,jpg,gif,svg',

        'body' => 'required',

    ]);

    $imageName = time().'.'.$request->image_file->getClientOriginalExtension();
    $request->image->move(public_path('image'), $imageName);

    auth()->user()->publish(

        new Post(request(['title','body']))
    );

    
    session()->flash('message', 'your post has now been published');

    
    return redirect('/');
}
1

1 Answers

1
votes

Looks like you should use image because you're validating image and not image_file:

$request->image->getClientOriginalExtension()