View:
<td>
<div >
<button type="button" onclick="location.href=' {{ route ('SupAd.View_PL_Accnt/{$id}') }}'" >
<i ></i>View
</button>
</td>
Route:
`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']));
}
View_PL_Accnt.blade.php :
<h3 >{{ data['name'] }}</h3>
Error:
Use of undefined constant data - assumed 'data' (this will throw an Error in a future version of PHP) (View: C:\Users\CuatrosMarias\Documents\GitHub\IPS\resources\views\dashboards\SupAd\pages\index\View_PL_Accnt.blade.php)
CodePudding user response:
typo error {{ $data['name'] }}
$
is missing at the view
CodePudding user response:
You need to send variables using with()
in your controller
return view('dashboards.SupAd.pages.index.View_PL_Accnt')->with('data',$data)->with('id',$id);
Your View Accnt.blade.php
you have used data as constant you need to use it as variable
Eloquent result gives object so you can access the name property of your result object like below
{{ $data->name }}
CodePudding user response:
Try this one works fine in my side always..
->with(compact('data', 'id'));