簡體   English   中英

從中獲取特定數據<div id="text_translate"><p>看法:</p><pre> <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></pre><p> 路線:</p><pre> `Route::get('View_PL_Accnt', [SupAdController::class, 'View_PL_Accnt'])->name('SupAd.View_PL_Accnt/{$id}');`</pre><p> Controller:</p><pre> 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'])); }</pre><p> 查看_PL_Accnt.blade.php:</p><pre> <h3 class="SupAd_name">{{ data['name'] }}</h3></pre><p> 錯誤:</p><p> 使用未定義的常量數據 - 假定為“數據”(這將在未來版本的 PHP 中引發錯誤)(視圖:C:\Users\CuatrosMarias\Documents\GitHub\IPS\resources\views\dashboards\SupAd\pages\index \View_PL_Accnt.blade.php)</p><p> <a href="https://i.stack.imgur.com/kbAZb.png" rel="nofollow noreferrer">錯誤</a></p></div>(使用 Id)在 Laravel<table> </table>

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM