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.
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.
@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');
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.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community