8000 Eloquent ::all() returns a Collection object from an empty table · Issue #79 · laravel/framework · GitHub
[go: up one dir, main page]

Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
driesvints opened this issue Jan 17, 2013 · 3 comments
Closed

Comments

@driesvints
Copy link
Member

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? :-/

@robclancy
Copy link
Contributor

Use

@If (count($users))

?

@driesvints
Copy link
Member Author

Ah yes, you're right. Sorry my bad. I was a bit confused by it returning an object.

@aaqibmehran
Copy link

I am new to laravel.
I have a eloquent model named Property. Now when I do
Property::where('user_id', 1)->get();
Like normal sql or codeigniter it doesn't returns array or std Class object but something like below. Help with this kindly.

Illuminate\Database\Eloquent\Collection Object
(
[items:protected] => Array
(
[0] => App\Property Object
(
[table:protected] => properties
[connection:protected] =>
[primaryKey:protected] => id
[keyType:protected] => int
[perPage:protected] => 15
[incrementing] => 1
[timestamps] => 1
[attributes:protected] => Array
(
[id] => 1
[title_en] => house
[title_ar] => مسكن
[address_en] => mecca saudi arabia
[address_ar] => مكة السعودية
[description_en] => this is very good house
[description_ar] => هذا هو منزل جيد جدا
[city] => 1
[built_year] => 2017
[type] => 2
[purpose] => 1
[bedrooms] => 2
[bathrooms] => 2
[kitchens] => 1
[garages] => 1
[features] =>
[security] => 10
[price] => 500
[pictures] => 1-1513600608-download.jpg,2-1513600560-download.jpg
[user_id] => 3
[created_at] =>
[updated_at] =>
)

dbpolito pushed a commit to dbpolito/framework that referenced this issue Oct 1, 2019
…thods

Make the framework more compatible with illuminate components
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
0