I have the following route
in my laravel
project
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>
Problem:
The problem is when I try to load the index
page, it shows me the following error
Use of undefined constant makes – assumed ‘makes’ (this will throw an Error in a future version of PHP) (View: /customers/6/1/4/alle-voertuigen.nl/httpd.www/resources/views/Index.blade.php)
I’ve visit all the possible links, and tried different ways of doing it, but nothing is working with me.
This is what it is showing when I do dd($makes)
, in attributes
I have the name
column
3
Answers
Use
with
in your controller.Should work.
If you use this way to return a view, you must use
with
to add parameters :I will advise to use the
view
helper, I don’t know what version of Laravel you use :Just only thing sure, it can’t work if you don’t pass variables as an array (with
compact
or['myVariable' => $var]
)its
index
notIndex