[英]Fetching particular data from <table> (using Id) in Laravel
看法:
<td>
<div class="template-demo">
<button type="button" onclick="location.href=' {{ route ('SupAd.View_PL_Accnt/{$id}') }}'" class="btn btn-outline-info btn-icon-text">
<i class="ti-search btn-icon-append"></i>View
</button>
</td>
路線:
`Route::get('View_PL_Accnt', [SupAdController::class, 'View_PL_Accnt'])->name('SupAd.View_PL_Accnt/{$id}');`
Controller:
public function View_PL_Accnt(Request $request){
$id = $request->id;
$data = User::find($id);
return view('dashboards.SupAd.pages.index.View_PL_Accnt', compact (['data', 'id']));
}
查看_PL_Accnt.blade.php:
<h3 class="SupAd_name">{{ data['name'] }}</h3>
錯誤:
使用未定義的常量數據 - 假定為“數據”(這將在未來版本的 PHP 中引發錯誤)(視圖:C:\Users\CuatrosMarias\Documents\GitHub\IPS\resources\views\dashboards\SupAd\pages\index \View_PL_Accnt.blade.php)
您需要在 controller 中使用with()
發送變量
return view('dashboards.SupAd.pages.index.View_PL_Accnt')->with('data',$data)->with('id',$id);
您的視圖Accnt.blade.php
您已將數據用作常量,您需要將其用作變量
Eloquent 結果給出 object 因此您可以訪問結果 object 的名稱屬性,如下所示
{{ $data->name }}
拼寫錯誤{{ $data['name'] }}
$
is missing at the view
試試這個在我身邊總是很好用..
->with(compact('data', 'id'));
看法:
<button type="button" onclick="location.href=' {{ route ('SupAd.View_PL_Accnt', [$user->id]) }}'" class="btn btn-outline-info btn-icon-text">
<i class="ti-search btn-icon-append"></i>View
</button>
路線:
Route::get('View_PL_Accnt/{id}', [SupAdController::class, 'View_PL_Accnt'])->name('SupAd.View_PL_Accnt');
Controller:
public function View_PL_Accnt($id){
$data = User::find($id);
return view('dashboards.SupAd.pages.index.View_PL_Accnt', compact (['data', 'id']));
查看_PL_Accnt.blade.php:
<h3 class="SupAd_name">{{ $data->name }}</h3>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.