【发布时间】:2021-01-19 22:37:02
【问题描述】:
好的,我想创建像这样在另一个页面中显示数据的路线
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)
]);
}
}
有错误
无法解析 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>
【问题讨论】:
-
添加您的
PengadaanController代码或您调用此组件的位置。? -
我需要使用控制器吗?
-
您在此处添加了
Route::get('/uraian/{id}', [PengadaanController::class, 'uraian'])->name('uraian');控制器,对吗? -
对,我加了