Laravel array_merge(): 参数 #2 不是数组

Laravel 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:array_merge() 中的错误异常:参数 #2 不是数组

您需要将 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'));
});