php - 使用未定义的常量 make - 假定为“makes”
问题描述
route
我的laravel
项目中有以下内容
Route::get('/',[
'uses' => 'MakeController@index'
]);
Controller
class MakeController extends Controller{
public function index(){
$makes = MakeType::all();
return View::make('Index', $makes);
// tried this
// return view('Index',compact('makes'));
}
}
index.blade.php
<select>
<option>Select Make</option>
@foreach($makes as $make)
<option>{{$make->name}}</option>
@endforeach
</select>
问题:
问题是当我尝试加载index
页面时,它显示以下错误
使用未定义的常量 make - 假定为“makes”(这将在 PHP 的未来版本中引发错误)(查看:/customers/6/1/4/alle-voertuigen.nl/httpd.www/resources/views/Index .blade.php)
我已经访问了所有可能的链接,并尝试了不同的方法,但没有什么对我有用。
这就是我这样做时显示的内容dd($makes)
,在attributes
我的name
专栏中
解决方案
with
在您的控制器中使用。
return View::make('Index')->with(compact('makes'));
应该管用。
推荐阅读
- java - 如何将 toArray 结果转换为 CompletableFuture
[] 类型? - powershell - 如何在 Powershell 中将数据从 XLSX 附加到 XLSX?
- r-markdown - Rmarkdown 未正确显示可折叠面板
- reactjs - 合并不兼容的类型。例如:类型“{}”不可分配给类型“{}”
- .htaccess - 在 htaccess 中重写文件夹名称
- javascript - 数组 + 矩阵 = 对象数组
- javascript - 如何将 JSON 对象的 JavaScript 数组绑定到 viewModel 中的对象列表。dotnetcore mvc
- laravel - Laravel 使用 datetime-local 进行验证
- node.js - 如何通过 mongoose 中的 slug 属性值而不是 id 查询特定的帖子?
- python - Python如何打印全栈,包括使用的魔术方法(dunder methods)?