skip to Main Content

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)

Error

4

Answers


  1. Chosen as BEST ANSWER

    View:

    <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:

     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']));
    

    View_PL_Accnt.blade.php :

     <h3 class="SupAd_name">{{ $data->name }}</h3>
    

  2. typo error {{ $data['name'] }} $ is missing at the view

    Login or Signup to reply.
  3. 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 }}
    
    Login or Signup to reply.
  4. Try this one works fine in my side always..

    ->with(compact(‘data’, ‘id’));

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search