I have encountered a problem that says “Undefined variables $menus” in my view folder.
Framework : Laravel 11 (latest)
My attempt : using php artisan view:clear already
this is my view folder
fresh_juices.blade.php
<table>
<tr>
<th>Menu</th>
<th>Price</th>
</tr>
@foreach ($menus as $menu) ----------> this line shows error
<tr>
<td>{{ $menu->menu }}</td>
<td>{{ $menu->price }}</td>
</tr>
@endforeach
this is my routes
web.php
use AppHttpControllersFreshjuicesController;
Route::get('/', function () {
return view('fresh_juices', [FreshjuicesController::class, 'index']);
});
this is my controller
FreshjuicesController.php
use AppModelsMenu_m;
class FreshjuicesController extends Controller
{
public function index()
{
$menus = Menu_m::select('menu', 'price')->get();
return view('fresh_juices', compact('menus'));
}
}
May you guys helping me to correct my code? Thank you in advance!
New contributor
user25591196 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.