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);
}
}
You can do:
Icon::all()->keyBy('name')
or
Icon::all()->keyBy('name')->toArray()
arjan said:
You can do:
Icon::all()->keyBy('name')
or
Icon::all()->keyBy('name')->toArray()
Perfect!
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community