我有一个非常简单的路线代码
Route::get("/{id}",function($id){
return view("post.posts",$id);});
以及视图中的简单代码:
<div><h1> hello .{{$id}} </h1></div>
但我得到一个例外:Factory.php 第 167 行中的 ErrorException:array_merge(): Argument #2 is not an array
我有一个非常简单的路线代码
Route::get("/{id}",function($id){
return view("post.posts",$id);});
以及视图中的简单代码:
<div><h1> hello .{{$id}} </h1></div>
但我得到一个例外:Factory.php 第 167 行中的 ErrorException:array_merge(): Argument #2 is not an array
你需要传递array
给你的视图,所以而不是
Route::get("/{id}",function($id) {
return view("post.posts",$id);
});
在你只传递字符串的地方,你应该使用:
Route::get("/{id}",function($id) {
return view("post.posts", ['id' => $id]);
});
或者:
Route::get("/{id}",function($id) {
return view("post.posts", compact('id'));
});