1 year ago

Undefined variable: data in view.

Posted 1 year ago by Kistlak

I'm creating a web site using a Laravel. Now I want to view all the data from the database called users. But, I got this error always - > Undefined variable: data (View: D:\wamp64\www\FinalProject\resources\views\AdminPanel.blade.php).

How can I fix this ??

Here is my Controller - AdminPanelController.php


namespace App\Http\Controllers;

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

class AdminPanelController extends Controller
    public function index()
        return view('AdminPanel');
    public function logout(Request $request)
     return redirect('/login');
    public function AdminView()
     return view('AdminPanel')->with('data',$data);

Here is my View - AdminPanel.blade.php

<table class="table table-bordered">

<td> Name </td>
<td> Email </td>
<td> Images </td>

@foreach($data as $value )
<td> {{ $value->name }} </td>
<td> {{ $value->email }} </td>
<td> <img src='{{ $value->filemove }}' style='width:100px;height:100px;'> </td>
<td> <a href="edit/{{ $value->id }}"><input type="submit" name="update" value="Update" class="btn-primary"></a> </td>
<td> <a href="delete{{ $value->id }}"><input type="submit" name="delete" value="Delete" class="btn-danger"></a> </td>

Here is my routes


| Web Routes
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!

Route::get('/', function () {
    return view('index');


Route::group(['middleware' => 'checkuser'],function(){
Route::get('/AdminPanel', '[email protected]')->name('AdminPanel');

Route::get('/AdminView', '[email protected]');

Please sign in or create an account to participate in this conversation.