1

我有一个非常简单的路线代码

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

4

1 回答 1

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'));
});
于 2018-09-16T07:14:54.710 回答