lundi 16 janvier 2017

ErrorException in BladeCompiler.php line 584: Undefined offset: 1

I'm learning Laravel and now I have faced a bad problem. Basically I have added a new controller called UsersController.php and I have set the route to that controller inside of web.php. Here's the controller:

    <?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class UsersController extends Controller
{
    public function index()
    {
        $users = [
            '0' => [
                'first_name' => 'Renato',
                'last_name' => 'Hysa',
                'location' => 'Albania'
            ],
            '1' => [
                'first_name' => 'Jessica',
                'last_name' => 'Alba',
                'location' => 'USA'
            ]
        ];
        return view('admin.users.index', compact('users'));
    }
}

So as you can see I have linked this to a blade which is inside of resources/views/admin/users and it is called index.blade.php and goes like this:

 @foreach($users as $user)
    <li>
    {!! $user['first_name'] !!} {!! $user['last_name'] !!}
    from {!! $user['location'] !!}
    </li>
@foreach

So when I goto this URL it must shows the users but instead of that it shows an error:

ErrorException in BladeCompiler.php line 584: Undefined offset: 1

Click to see the print screen of my page

And unfortunately I know nothing about what's going on there. I'm pretty sure that I have added everything correctly because I'm following a Youtube tutorials playlist and you can goto this link to see how it should be shown on the browser.

So if you know whats going wrong here please let me know.. Thanks!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire