【问题标题】:Laravel array_merge(): Argument #2 is not an arrayLaravel array_merge():参数 #2 不是数组
【发布时间】:2018-09-16 15:14:54
【问题描述】:
我有一个非常简单的路线代码
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
【问题讨论】:
标签:
laravel
laravel-5
laravel-blade
laravel-5.7
【解决方案1】:
您需要将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'));
});