0

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.

Odin Thunder
  • 3,284
  • 2
  • 28
  • 47
Faisal Hilmi
  • 43
  • 1
  • 8
  • Could you try to pinpoint the exact location of the error? Because the error is thrown in helpers.php, but that's not where the error began. – Douwe de Haan May 09 '17 at 06:57
  • @DouwedeHaan the complete error message is htmlentities() expects parameter 1 to be string, array given (View: /home/faisal/wgs/paskomnasdev/paskomnas/resources/views/admin/product/create.blade.php),,,,and the blade is on thepasteb.in – Faisal Hilmi May 09 '17 at 07:00
  • Have you tried using ..`->withInput($request->all())->with(....)` Check http://stackoverflow.com/questions/31081644/how-to-redirect-back-to-form-with-input-laravel-5 – VijayRana May 09 '17 at 07:00
  • @FaisalHilmi at what line in that view are you getting the error? – Douwe de Haan May 09 '17 at 07:01
  • @DouwedeHaan i dont know, but i just try to remove all input form except the form::text('name') and its worked – Faisal Hilmi May 09 '17 at 07:05
  • @vijayrana oke i will try, edited, i use $request->all() and still not working :( – Faisal Hilmi May 09 '17 at 07:05

2 Answers2

3

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!');
  }
AddWeb Solution Pvt Ltd
  • 21,025
  • 5
  • 26
  • 57
0

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

return redirect()->back()->with('error', 'Error Message');
Webdesigner
  • 1,954
  • 1
  • 9
  • 16