Autista_z
Autista_z

Reputation: 2541

Eloquent (Laravel) result to array

I am trying to get result from Eloquent (Laravel 4.2) into simple array, so I con make array_diff.

In documentation I found all() function, which gives result to array, but the are also things I cant have, because of array_diff.

I have :

$curCentres = Doccentre::where('r_document', $document)->select('r_id')->get()->all();

but this return something like:

array(2) { 
    [0]=> object(Doccentre)#1125 (20) {
         ["table":protected]=> string(9) 
            "doccentre" ["primaryKey":protected]=> string(4) 
            "r_id" ["timestamps"]=> bool(false) 
            ["connection":protected]=> NULL 
            ["perPage":protected]=> int(15) 
            ["incrementing"]=> bool(true) 
            ["attributes":protected]=> array(1) {
                 ["r_id"]=> string(1) "1" 
            } 
            ["original":protected]=> array(1) { 
                ["r_id"]=> string(1) "1" 
            }
            ["relations":protected]=> array(0) { } 
            ["hidden":protected]=> array(0) { } 
            ["visible":protected]=> array(0) { } 
            ["appends":protected]=> array(0) { } 
            ["fillable":protected]=> array(0) { } 
            ["guarded":protected]=> array(1) { 
                [0]=> string(1) "*" 
            } 
            ["dates":protected]=> array(0) { } 
            ["touches":protected]=> array(0) { } 
            ["observables":protected]=> array(0) { } 
            ["with":protected]=> array(0) { } 
            ["morphClass":protected]=> NULL 
            ["exists"]=> bool(true) 
        } 
    [1]=> object(Doccentre)#1124 (20) { 
        ["table":protected]=> string(9) 
        "doccentre" ["primaryKey":protected]=> string(4) 
        ....
} 

All I need is :

array(2) { [0]=> string(1) "1" [1]=> string(1) "2" } 

Is there any way to get it? I also tried toArray(), but it makes only errors.

Upvotes: 2

Views: 2967

Answers (1)

Zakaria Acharki
Zakaria Acharki

Reputation: 67505

You could use lists to retrieving a list of column values:

$curCentres = Doccentre::where('r_document', $document)->lists('r_id');

Hope this helps.

Upvotes: 4

Related Questions