livewire 中的路由/$id 无法访问数据

route /$id in livewire cant access data

好的,我想创建像这样在另一个页面中显示数据的路由

http://localhost:8000/uraian/1

我的路线是这样的

Route::get('/uraian/{id}', [PengadaanController::class, 'uraian'])->name('uraian');

我可以访问这个和它的正常。现在是我的 livewire 功能

<?php

namespace App\Http\Livewire;

use Livewire\WithPagination;

use App\Models\Kegi;

use App\Models\Uraian;

use Livewire\Component;

class UraianLw extends Component

{

    use WithPagination;
       public $uraianid ,$kegiatan_id ,$kode_rekening ,$uraian ,$anggaran ;




    public function render($id)

    {

        $kegiatan = Kegi::findOrFail($id);// here the problem

        $newid = $kegiatan->id ;

        

        return view('livewire.uraian-lw',[

            'uraian' => Uraian::where('id' ,$newid)->where('uraian', 'like', '%'.$this->search.'%')->paginate(10)

        ]);

    }
}

有错误

Unable to resolve dependency [Parameter #0 [ $id ]] in class App\Http\Livewire\Uraian

如何解决这个问题?

#update its my blade

<x-app-layout>
<x-slot name="header">
    <h2 class="font-semibold text-xl text-gray-800 leading-tight">
        {{ __('Dashboard') }} 
    </h2>
</x-slot>


     @livewire('uraian-lw')
           
    

</x-app-layout>

你应该使用这个

<x-app-layout>
<x-slot name="header">
    <h2 class="font-semibold text-xl text-gray-800 leading-tight">
        {{ __('Dashboard') }} 
    </h2>
</x-slot>


     @livewire('uraian-lw',['id' => Route::current()->parameter('id')]) <----------------- pass id from blade
           
    

</x-app-layout>

App\Http\Livewire\UraianLw.php

<?php

use Livewire\Component;
use App\Models\Kegi;
use App\Models\Uraian;


class UraianLw extends Component

{

    use WithPagination;
    public $uraianid, $kegiatan_id, $kode_rekening, $uraian, $anggaran, $newid;


    public function mount($id)
    {
        $kegiatan = Kegi::findOrFail($id);
        $this->newid = $kegiatan->id;
    }

    public function render()

    {
        return view('livewire.uraian-lw', [

            'uraian' => Uraian::where('id', $this->newid)->where('uraian', 'like', '%' . $this->search . '%')->paginate(10)

        ]);
    }
}