lundi 8 février 2016

Laravel 5.2 - Change Data Format get from Eloquent

I have a model like this-

$feature_project = FeatureProject::select(
                                                'feature_id'
                                            )
                                            ->where('project_id', $project->id)
                                            ->get();

And if I return it, I am getting a output like this-

[{"feature_id":2},{"feature_id":4},{"feature_id":9}]

But I want t output like this-

[2,4,9]

So I need to convert the output.

But I am not finding a way without using for-each loop (make a temp array, push all elements to that array from current array with a for-each loop).

But I think there is more smart way than that in Laravel to do that.

I think Laravel Collection is used for this purpose.

But I am not familiar with it.

Can anyone help me please?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire