Support the ongoing development of Laravel.io →
Laravel Views
Last updated 2 years ago.
0

Hi!

It's odd that it's not passing the data. Instead of:

return view('AdminPanel')->with('data',$data);

try

return view('AdminPanel',['data'=>$data]);

And post your results.

Last updated 6 years ago.
0
moderator

Your index action returns the same view but without any data, so I suspect that you visit /AdminPanel and get this error.

If you visit /AdminView you should get the page you want to see.

0

@Chris - I have updated my Controller and routes as below. I didn't change View file and I still get same error as this - "Undefined variable: data (View: D:\wamp64\www\FinalProject\resources\views\AdminPanel.blade.php)"

AdminPanelController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\User;

class AdminPanelController extends Controller
{
    public function index()
    {
        $data = User::all();
        //$data = login::orderBy('created_at', 'desc')->get();
        return view('AdminPanel', ['data' => $data]);
    }
    
    public function logout(Request $request)
    {
     $request->session()->flush();
     return redirect('/login');
    }
       
}

Route

Route::get('/AdminPanel', 'AdminPanelController@index')->name('AdminPanel');
0

Try making a simple test and just pass a simple value instead of a model.

eg.

    public function index()
    {
        $data = 'this is a test';
        return view('AdminPanel', compact(['data']));
    }
    
...8<...

Then simplify your view so it just shows $data

{{ $data }}

Then once you establish you're passing data you can change it to the model. Make sure $data is set before calling the view by adding in a dd($data) so you can be sure it is set.

Last updated 6 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.