I keep getting Undefined variable: cars when loading the page in Laravel.
I have the following code:
web.php
Route::get('/cars', function () {
$cars= Car::select('brand')->get();
return view('test.cars')->with(compact($cars));
});
If I put dd(cars); before return view the collection is outputted.
In cars.blade.php I have the following code:
<select name="car">
@foreach($cars as $car)
<option>{{ $car->brand}}</option>
@endforeach
</select>
and I get Undefined variable: cars, I also removed the dropdown from blade template and I tried {{ dd($cars) }} but get the same error.