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

El-7's avatar
Level 1

Unable to resolve dependency [Parameter #0 [ <required> $id ]] in class App\Http\Livewire\Blog\ShowPost

When I want to render the ShowPost component I faced this error

this is the route:

Route::get('/blog/{id}', function () { return view('pages/show-post'); })

this is the show-post.blade.php

@extends('pages.ShowLayout')

@section('content')

<header class="header-image ken-burn-center light" data-parallax="true" data-natural-height="1080" data-natural-width="1920" data-bleed="0" data-image-src="http://via.placeholder.com/1920x1080" data-offset="0" style="margin-top: 120px;">
    <div class="container" style="margin-top: 0px; opacity: 1;">
        <h1>{{ __("The Blog")}}</h1>
        <h2>{{__("The best view comes after hardest climb")}}</h2>
        <ol class="breadcrumb">
            <li><a href="index.html">{{__('Home')}}</a></li>
            <li><a href="#">{{__("Pages")}}</a></li>
            <li><a href="#">{{__("Blog")}}</a></li>
        </ol>
    </div>
</header>
<main>
    <section class="section-base section-color">
        <div class="container">
            <div class="row">
               @livewire('blog.show-post')
                
               @livewire('blog.categories')
            </div>
        </div>
    </section>
</main>

@endsection

and this is the component Class:

class ShowPost extends Component { public $post; public $local;

public function mount($id){
    $this->local = app()->getLocale();
    $this->post = Blog::find($id);
}



public function render()
{
    return view('livewire.blog.show-post')
    ->extends('pages.ShowLayout')
    ->section('content');
}

}

0 likes
10 replies
El-7's avatar
Level 1

I used it like this:

@livewire('blog.show-post', ['id' => $id])

and now it shows:

Undefined variable: id (View: C:\xampp\htdocs\Hikeventure\resources\views\pages\show-post.blade.php)

Sinnbeck's avatar

You need to pass it to the view

Route::get('/blog/{id}', function ($id) { return view('pages/show-post', compact('id') ); })
1 like
Sinnbeck's avatar

Use dd() to debug your code. Check if you get a proper id

public function mount($id){
dd($id);
 $this->post = Blog::find($id); 
dd($this->post);
 $this->local = app()->getLocale(); 
}
1 like
El-7's avatar
Level 1

It solved Thanks a lot!

esra's avatar

@El-7 How to solve this problem? I have the same problem and I cant fix it.

razorext2's avatar

@esra just pass id parameter to the view

if u mixing fullpage blade component with livewire component, makesure to pass the id to the livewire component on the blade component

so it will be like @livewire('your-component', ['params' => $value])

Chris1989's avatar

I have the same problem and i cant fix it, I get error: Unable to resolve dependency [Parameter #1 [ <required> $action ]] i have a simple button like this : wire:click="success ({{ $service->id }},0)" And a simple function :

public function success($serviceID,$action)
{  
    
    $data = [
     
        'success'  => $action,
    ];    
    service::find($serviceID)->update($data);
    
}

the data passing correctly through the query, but i get that error and after refresh the page i can see the updated data, i cant find solution.

acarbey15@gmail.com's avatar

Upgrade this function

public function success($serviceID=null,$action=null)
{  
    
    $data = [
     
        'success'  => $action,
    ];    
    service::find($serviceID)->update($data);
    
}

my functions like this


 function save($key = null)
    {
        $item = @$this->items[$key];
        if ($item) {
            Trans::where('id', $item['id'])->update(['value' => $item['value']]);
            $this->emit('toast', AcrTrans('Update success'), 'success');
        }
    }

Please or to participate in this conversation.