Support the ongoing development of Laravel.io →
Database Eloquent Installation
Last updated 1 year ago.
0

You should consider overriding the toArray() method in your collection class. It should be pretty easy to implement.

<?php namespace Extensions;

class CustomCollection extends \Illuminate\Database\Eloquent\Collection {
    public function toArray()
    {
        // ...Your own implementation...
    }
}

class Icons extends Eloquent {
    // Override the parent method
    public function newCollection(array $models = Array())
    {
        return new Extensions\CustomCollection($models);
    }
}

Last updated 8 years ago.
0
Solution

You can do:

Icon::all()->keyBy('name')

or

Icon::all()->keyBy('name')->toArray()
0

arjan said:

You can do:

Icon::all()->keyBy('name')

or

Icon::all()->keyBy('name')->toArray()

Perfect!

0

Sign in to participate in this thread!

Eventy

Your banner here too?

resmall resmall Joined 24 Aug 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.