如何在laravel 5中使用return back() - > withInput()

i always get error like this when i use withInput() function in return back() but when i dont use withInput() this error wont appear.

ErrorException in helpers.php line 469: htmlentities() expects parameter 1 to be string, array given

this the validation code

$validation = Validator::make($request->all(), [
    'name'         => 'required|unique:products', 
    'category_id'  => 'required', 
    'region'       => 'required', 
    'primary_image'=> 'required'
]);

if($validation->fails()) {
    return back()->withInput()
        ->with('error', 'Please upload the image!');

and for the view, this is the full trace code: https://thepasteb.in/p/pghNcGOzPAqZncN

i want when the validation is fail, it will back with previous input. hope you can give me solution :) thankyou.

I think you need to try this:

 if($validation->fails()) {
    return redirect()->back()->withErrors($validator) ->withInput();
  }

OR

 if($validation->fails()) {
    return redirect()->back()->withInput()->with('error', 'Please upload the image!');
  }

I just use this, and it works for me all the time:

return redirect()->back()->with('error', 'Error Message');