好吧,我想创建这样的路线,例如在另一个页面中显示数据
http:// localhost:8000 / uraian / 1
我这样的路线
Route::get('/uraian/{id}', [PengadaanController::class, 'uraian'])->name('uraian');
我可以访问它和它的normal。现在是我的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)
]);
}
}
有错误
无法解析类App \ Http \ Livewire \ Uraian中的依赖项[Parameter#0 [$ id]]
如何解决这个问题?
#更新其刀片
<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>
答案 0 :(得分:0)
您应该使用此
<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>
<?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)
]);
}
}