【问题标题】:Type error: Argument 2 passed to with() must be callable or null, object given类型错误:传递给 with() 的参数 2 必须是可调用的或 null,给定对象
【发布时间】:2018-03-26 11:43:02
【问题描述】:
Route::get('/',function (){
    $collection = collect(['product'=>'chair','price'=>100]);    
    //dd($collection);
    return view('welcome')-with('prices',$collection);
});

我想在视图中传递 $collection 但我收到此错误:

类型错误:传递给 with() 的参数 2 必须是可调用的或为 null,

给定对象

我不明白为什么。

谁能解释一下?

【问题讨论】:

  • 好像有错字,忘记箭头了

标签: php laravel-5 collections


【解决方案1】:

使用->with 代替-with

return view('welcome')->with('prices',$collection);

【讨论】:

  • 请设置代码样式并添加关于您的代码的小代码描述。
【解决方案2】:

试试这个

    $page_data = array(
      'product'=>'chair',
      'price'=>100
    );
return \View::make('welcome', $page_data);
or
return view('welcome', $page_data);

【讨论】:

  • 未定义变量:我尝试发送时的 page_data
  • $page_data = array('product'=>'chair', 'price'=>100); return view('welcome', $page_data);
  • 放入 dd($page_data) 并检查
  • array:2 [▼ "product" => "chair" "price" => 100 ]
  • 但是当我要迭代什么时
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-05-26
  • 2019-06-17
  • 2023-02-10
  • 1970-01-01
  • 1970-01-01
  • 2018-04-19
  • 1970-01-01
相关资源
最近更新 更多