【问题标题】:How to use return back()->withInput() in laravel 5如何在 laravel 5 中使用 return back()->withInput()
【发布时间】:2023-03-16 21:17:01
【问题描述】:

当我在 return back() 中使用 withInput() 函数时,我总是会遇到这样的错误 但是当我不使用 withInput() 这个错误不会出现。

helpers.php 第 469 行中的 ErrorException:需要 htmlentities() 参数1为字符串,给定数组

这是验证码

$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!');

对于视图,这是完整的跟踪代码: https://thepasteb.in/p/pghNcGOzPAqZncN

我希望当验证失败时,它会返回之前的输入。 希望你能给我解决方案:) 谢谢。

【问题讨论】:

  • 您能尝试找出错误的确切位置吗?因为错误是在 helpers.php 中抛出的,但这不是错误开始的地方。
  • @DouwedeHaan 完整的错误消息是 htmlentities() 期望参数 1 是字符串,给定数组(查看:/home/faisal/wgs/paskomnasdev/paskomnas/resources/views/admin/product/create .blade.php),,,,并且刀片在 thepasteb.in 上
  • 你试过用..->withInput($request->all())->with(....)检查stackoverflow.com/questions/31081644/…
  • @FaisalHilmi 在该视图的哪一行出现错误?
  • @DouwedeHaan 我不知道,但我只是尝试删除除 form::text('name') 及其工作之外的所有输入表单

标签: php laravel redirect laravel-5


【解决方案1】:

我只是使用它,它一直对我有用:

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

【讨论】:

    【解决方案2】:

    我认为你需要试试这个:

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

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

    【讨论】:

      猜你喜欢
      • 2016-10-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-16
      相关资源
      最近更新 更多