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

sav*_*lin 1 php collections laravel-5

Route::get('/',function (){
    $collection = collect(['product'=>'chair','price'=>100]);    
    //dd($collection);
    return view('welcome')-with('prices',$collection);
});
Run Code Online (Sandbox Code Playgroud)

我想在视图上传递 $collection 但出现此错误:

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

给定对象

我不明白为什么。

有人能给我解释一下吗?

小智 6

使用->with而不是-with

return view('welcome')->with('prices',$collection);
Run Code Online (Sandbox Code Playgroud)