好的,我想创建像在另一个页面中显示数据的路由,就像这样
http://localhost:8000/uraian/1
我的路线是这样
`Route::get('/uraian/{id}', [PengadaanController::class, 'uraian'])->name('uraian');`我可以访问这个和它的正常。现在这是我的直播功能
<?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中的依赖关系[参数#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>发布于 2020-10-05 04:00:54
你应该用这个
<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)
]);
}
}https://stackoverflow.com/questions/64202238
复制相似问题