View:
<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:
`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 class="SupAd_name">{{ data['name'] }}</h3>
Error:
Use of undefined constant data – assumed ‘data’ (this will throw an Error in a future version of PHP) (View: C:UsersCuatrosMariasDocumentsGitHubIPSresourcesviewsdashboardsSupAdpagesindexView_PL_Accnt.blade.php)
4
Answers
View:
Route:
Controller:
View_PL_Accnt.blade.php :
typo error
{{ $data['name'] }}
$
is missing at the viewYou need to send variables using
with()
in your controllerYour View
Accnt.blade.php
you have used data as constant you need to use it as variableEloquent result gives object so you can access the name property of your result object like below
Try this one works fine in my side always..