FAQ
Frequently asked questions about theme development for the lara-app platform.
How do I debug variable data?
Use Laravel's dump() or dd() in Blade:
{{-- Print a variable's contents without stopping execution --}}
{{ dump($page->settings) }}
{{-- Print and STOP (die-dump) --}}
{{ dd($page->misc) }}
{{-- @php block for multiple vars --}}
@php
dump($themes);
dump(featureProducts(2));
@endphp
How do I get the site's base URL?
How do I link to another page?
Use customUrl() for named routes, or route() for named Laravel routes:
{{-- Named application pages --}}
<a href="{{ customUrl('login') }}">Login</a>
<a href="{{ customUrl('cart_list') }}">Cart</a>
{{-- Full Laravel route names --}}
<a href="{{ route('user.register', [], false) }}">Register</a>
How do I show social login buttons?
@if(!empty($page->settings->google_status) && (int)$page->settings->google_status === 1)
<a href="{{ hybridAuth(route('user.login', [], false), 'google') }}">Login with Google</a>
@endif
How do I display flash messages?
@php $flash = flashMessenger(); @endphp
@foreach($flash->getSuccessMessages() as $msg)
<div class="alert alert-success">{{ $msg }}</div>
@endforeach
@foreach($flash->getErrorMessages() as $msg)
<div class="alert alert-danger">{{ $msg }}</div>
@endforeach
How do I check if a user is logged in?
{{-- Method 1: Laravel auth guard --}}
@auth('customer')
<p>Logged in!</p>
@endauth
{{-- Method 2: $page->user --}}
@if($page->user)
<p>Logged in as {{ $page->user->email }}</p>
@endif
{{-- Method 3: identity() helper --}}
@if(identity())
<p>User ID: {{ identity() }}</p>
@endif
How do I show products on the homepage?
@foreach(featureProducts(8) as $product)
<div>
<img src="{{ $product['image'] }}" alt="{{ $product['name'] }}">
<a href="{{ $product['detailUrl'] }}">{{ $product['name'] }}</a>
<span>${{ tagPrice($product['specialPrice']) }}</span>
</div>
@endforeach
How do I format a price?
${{ tagPrice(1250.99) }} {{-- Output: 1250.99 --}}
${{ tagPrice(1250.99, true) }} {{-- Output: 1,250.99 --}}
How do I hide the cart in catalog mode?
How do I show the cart item count in the header?
How do I load a theme asset (CSS/JS/image)?
{{-- CSS --}}
<link rel="stylesheet" href="{{ theme_asset('css/style.css') }}">
{{-- JS --}}
<script src="{{ theme_asset('js/app.js') }}"></script>
{{-- Image --}}
<img src="{{ theme_asset('images/logo.png') }}" alt="Logo">
How do I get menus from the admin panel?
@foreach(getMenu('top') as $menu)
<a href="{{ $menu['menu_url'] }}">{{ $menu['menuName'] }}</a>
@endforeach
How do I access $themes settings safely with a default?
{{-- Use null coalescing to provide a fallback --}}
<div style="background: {{ $themes->product_background_color ?? '#ffffff' }}">
Can I add raw PHP in a Blade template?
Yes, using the @php directive:
@php
$discountedPrice = $product['specialPrice'];
$savings = $product['normalPrice'] - $discountedPrice;
@endphp
<p>Save ${{ tagPrice($savings) }}!</p>
How do I include a partial?
{{-- Basic include --}}
@include('partial.header')
{{-- Include with data --}}
@include('partial.productcard', ['product' => $myProduct, 'showCart' => true])
How do I emit raw HTML from a helper?
{{-- Wrong - will escape the HTML --}}
{{ getMenuContent('about-us') }}
{{-- Correct - renders HTML as-is --}}
{!! getMenuContent('about-us') !!}
What is the $loop variable in @foreach?
Blade provides a $loop variable inside every @foreach:
@foreach($products as $product)
@if($loop->first) <div class="first-item"> @endif
<div>
{{ $loop->iteration }} / {{ $loop->count }} — {{ $product['name'] }}
</div>
@if($loop->last) </div> @endif
@endforeach
$loop property |
Description |
|---|---|
$loop->index |
0-based current index |
$loop->iteration |
1-based current iteration |
$loop->first |
true on first iteration |
$loop->last |
true on last iteration |
$loop->count |
Total items in the array |
$loop->remaining |
Items remaining |
$loop->even |
true if even-numbered iteration |
$loop->odd |
true if odd-numbered iteration |
$loop->depth |
Nesting depth (for nested loops) |