You will need to show us your routes file and/or controller.
One thing that jumps out is @foreach ( $customer as $customer); should it be $customers as $customer?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi guys,
I am working on an application and as part of that app, when the user logins in (admin), it brings you to a admin page that will display the DB. When I pass in the credentials, the route works as the url changes to the correct blade but I get a "undefined variable" error and that variable is a table in the DB (customer), any ideas? Im pretty sure the code is all over the place at this stage as Ive been wrestling with it so long, chopping and changing
THIS IS THE BLADE TEMPLATE
@extends('layouts.layout')
@section('content')
<div class="col-lg-6">
<h3>Customer Table</h3>
@foreach ( $customer as $customer)
<!--Display customers table-->
<h2>{{ $customer->custID }} <small>{{ $customer->name }}: {{ $customer->number }}:{{ $customer->email }}: {{ $customer->comments }}:{{ $customer->bookingID }}</small></h2>
@endforeach
<!-- Display bookings table -->
<h3>Booking Table</h3>
@foreach ($bookings as $booking)
<p>{{ $booking->bookingID }}:{{ $booking->custID }}:{{ $booking->productID }}</p>
@endforeach
<!-- Display Products table -->
<h3>Products Table</h3>
@foreach($products as $product)
<p>{{ $product->productID }}:{{ $product->name }}:{{ $product->description }}</p>
@endforeach
</div><!-- col-lg-6 -->
@endsection
THIS is the ROUTES file
That routes file is a bit of a mess... you have multiple definitions for some URIs. The routes file is read from top to bottom, so the first match will be used.
I notice that there are views being returned from the closures in some of the earlier route definitions; if these are the offending routes, then you are doing nothing to pass data from into the view.
I would suggest tidying up your routes file first, removing any routes that you are not using. If you are new to all of this, just use closure routes for now, e.g.
Route::get('home', function () {
// Example queries, yours might be more specific
$customers = App\Customer::all();
$bookings = App\Booking::all();
$products = App\Product::all();
// return the view along with the data
return view('enquiries', compact('customers', 'bookings', 'products'));
});
The compact() function creates an associative array of the specified variables which you can then use inside your view:
compact('customers', 'bookings', 'products');
// is equivalent to
[
'customers' => $customers,
'bookings' => $bookings,
'products' => $products
]
Please or to participate in this conversation.