Skip to content

Authentication & User Helpers


auth('customer') — Laravel Auth

The standard Laravel auth() helper is available in all templates. The customer guard is named 'customer'.

{{-- Check if a user is logged in --}}
@if(auth('customer')->check())
    <p>Welcome back!</p>
@else
    <a href="{{ customUrl('login') }}">Please log in</a>
@endif

{{-- Get the current user object --}}
@php $customer = auth('customer')->user(); @endphp
@if($customer)
    <p>Email: {{ $customer->email }}</p>
@endif

{{-- Get the current user ID --}}
@php $customerId = auth('customer')->id(); @endphp

identity(): ?int

Shortcut helper. Returns the currently logged-in customer's ID, or null for guests.

@php $customerId = identity(); @endphp
@if($customerId)
    <p>Your customer ID is: {{ $customerId }}</p>
@endif

lmcUserDisplayName(): string

Returns the full display name (first + last name) of the currently authenticated customer. Returns an empty string for guests.

@if(auth('customer')->check())
    <span>Hello, {{ lmcUserDisplayName() }}!</span>
@endif

bulkBuyer(): bool

Returns true if the current customer has the "Bulk Buyer" flag set (is_bulk_buyer = 'Y'). Bulk buyers typically get special pricing (e.g., free shipping).

@if(bulkBuyer())
    <div class="alert alert-info">
        🎉 You are a bulk buyer! Enjoy free shipping on all orders.
    </div>
@endif

{{-- Commonly used in order invoice to zero out shipping cost --}}
@php $shippingCost = bulkBuyer() ? 0 : $order->shippingAmount; @endphp
<td>Shipping: ${{ tagPrice($shippingCost) }}</td>

isAdminLogin(): bool

Returns true if the current "customer" session is actually an administrator logged in via the guest admin feature. Useful for showing admin-only badges or edit links while previewing the store as a customer.

@if(isAdminLogin())
    <div class="admin-badge">Admin Preview Mode</div>
    <a href="{{ url('/admin/product/edit/' . $product['productId']) }}" target="_blank">
        Edit This Product (Admin)
    </a>
@endif

flashMessenger(): object

Returns an object for reading flash messages stored in the session. This is the bridge between backend operations (like form submissions) and the UI.

Methods:

Method Returns Description
getSuccessMessages() array<string> Success flash messages
getErrorMessages() array<string> Error flash messages
getMessages() array<string> General flash messages
@php $flash = flashMessenger(); @endphp

{{-- Display success messages --}}
@foreach($flash->getSuccessMessages() as $msg)
    <div class="alert alert-success">
        <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
        {{ $msg }}
    </div>
@endforeach

{{-- Display error messages --}}
@foreach($flash->getErrorMessages() as $msg)
    <div class="alert alert-danger">
        <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
        {{ $msg }}
    </div>
@endforeach

getCart(?string $filter = null)

Retrieves shopping cart data for the current session. Can return the full cart details or a simple count.

Signature:

function getCart(?string $filter = null): mixed

$filter value Return type Description
null array Full cart details (items, totals, tax, etc.)
'cartProductCount' int Number of unique products in the cart
'cartProductQuantity' int Total item quantity (sum of all item quantities)
{{-- Header cart badge --}}
<a href="{{ customUrl('cart_list') }}" class="btn btn-warning">
    Cart <span class="badge bg-danger">{{ getCart('cartProductQuantity') }}</span>
</a>

{{-- Access full cart on the cart page --}}
@php $cart = getCart(); @endphp
<p>Subtotal: ${{ tagPrice($cart['subTotal'] ?? 0) }}</p>
<p>Tax: ${{ tagPrice($cart['taxAmount'] ?? 0) }}</p>
<p>Total: ${{ tagPrice($cart['grandTotal'] ?? 0) }}</p>

getcookie(string $name): ?string

Reads a cookie value from the current request.

@php $cookieValue = getcookie('my_preference'); @endphp

getquery(string $key, mixed $default = null): mixed

Reads a query string parameter from the current URL.

{{-- Check if we're on the Q&A tab of a product page --}}
@php $isQaTab = getquery('qaTab'); @endphp