Kistlak

@skliche - 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', '[email protected]')->name('AdminPanel');
Snapey
Snapey
3 months ago (865,465 XP)

And what does your AdminPanel.blade.php look like?

Kistlak

@Snapey - Here it is.. AdminPanel.blade.php

<table class="table table-bordered">

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


@foreach($data as $user )
<tr>
<td> {{ $user ->name }} </td>
<td> {{ $user ->email }} </td>
<td> <img src='{{ $user ->filemove }}' style='width:100px;height:100px;'> </td>
<td> <a href="edit/{{ $user ->id }}"><input type="submit" name="update" value="Update" class="btn-primary"></a> </td>
<td> <a href="delete{{ $user ->id }}"><input type="submit" name="delete" value="Delete" class="btn-danger"></a> </td>
</tr>
@endforeach
</table>
skliche
skliche
3 months ago (147,190 XP)

That still fails with Undefined variable: data? Do you get a trace with a line number where it fails? In /storage/framework/views you'll find the compiled views. One of them is the one where it fails and the line number will match there, not in your AdminPanel.blade.php file.

Kistlak

@skliche -

<table class="table table-bordered">

<tr>
<td> Name </td>
<td> Email </td>
</tr>


<?php $__currentLoopData = $data; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $value): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
<tr>
<td> <?php echo e($value->name); ?> </td>
<td> <?php echo e($value->email); ?> </td>
<?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
</table>
skliche
skliche
3 months ago (147,190 XP)

And is it reporting that it fails in line 9? What happens when you do a dd($data); before you return the view?

Cronix
Cronix
3 months ago (386,220 XP)

try running artisan view:clear to clean out the cached view files.

Snapey
Snapey
3 months ago (865,465 XP)

Is that your entire view? It does not extend any other layout?

Its time to hit us with the complete error message. Go on, we can take it...

Kistlak

I fixed my AdminPanelController.php like this.

public function index()
    {
      $data = User::all();
      //$data = login::orderBy('created_at', 'desc')->get();
      return view('AdminPanel', ['data' => $data]);
    }

And after I did a php artisan view::clear as @Cronix said and problem solved.

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