首页 > 解决方案 > 使用未定义的常量 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专栏中

在此处输入图像描述 请帮助我,谢谢

标签: phplaravel

解决方案


with在您的控制器中使用。

return View::make('Index')->with(compact('makes'));

应该管用。


推荐阅读