Skip to content

Eloquent ::all() returns a Collection object from an empty table #79

Closed
@driesvints

Description

@driesvints

I might be doing something wrong here but I followed the very basic example from the docs.

I'm simple retrieving all the users from the database which is empty but I get a Collection object back with 2 protected variables so my result isn't really 'empty'.

PHP code in the Controller:

class UsersController extends BaseController {

    public function index()
    {
        $users = User::all();
        var_dump($users);

        return View::make('admin.users.index')->with('users', $users);
    }

}

Response from var_dump:

object(Illuminate\Database\Eloquent\Collection)#130 (2) { ["items":protected]=> array(0) { } ["dictionary":protected]=> array(0) { } }

This means that I can't do the following in a Blade view because it will always pass the if statement:

@if($users)

The user model is pretty basic:

class User extends Eloquent {

    protected $table = 'users';

}

Any ideas? :-/

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions