Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

codingwithrk's avatar

Help me in Volt

<?php

use function Livewire\Volt\{state, title, layout};

state(['slug'])->url();
layout('components.layouts.app');
title('Course details');

?>
@php
    $data = \App\Models\Course::where(['status' => 1, 'slug' => $slug])->first();
@endphp

<div class="container mx-auto">
    <div class="my-5">
        <figure class="flex justify-center">
            <img src="{{ asset('storage/' . $data->image) }}"
                 alt="{{ $data->slug }}"/>
        </figure>
        <h2 class="text-5xl my-3 font-bold text-center">{{ $data->title }}</h2>
        <div class="text-justify">
            {!! $data->description !!}
        </div>
    </div>
</div>

This is my volt view page

Volt::route('course-details/{slug}', 'course-details')->name('course-details');

This is my route

I want to get course data inside of

<?php

use function Livewire\Volt\{state, title, layout};

state(['slug'])->url();
layout('components.layouts.app');
title('Course details');

?>

this only please help me to how to achieve that

And In Another page

I am unable to pass $links i am getting undefined variable error before Adding new class i didn't got error.

0 likes
1 reply
vincent15000's avatar
Level 63

The state allows you to declare accepted properties, it's the equivalent to the props in VueJS.

https://livewire.laravel.com/docs/volt#rendering-and-mounting-components

If you need to pass additional properties (additional to the public properties), you can use with().

public function with(): array
{
    return [
        'links' => [
        	[
            	'route' => route('home'),
            	'name' => 'Home',
        	],
        	[
            	'name' => 'Courses',
			],
    ];
}

https://livewire.laravel.com/docs/volt#providing-additional-view-data

Please or to participate in this conversation.