Not sure if this is the cleanest approach, but I made it work by returning a collection.
use Illuminate\Support\Collection; public function getFooBarAttribute() { return new Collection(array('foo','bar')); }
mattsears18 said:
The next to last code snippet on this page (http://laravel.com/docs/eloquent) shows how to define custom attributes on a model. Can a custom attribute return an array? For example:
public function getFooBarAttribute() { return array('Foo', 'Bar'); }
I get "Array to string conversion" errors when I try this. Any ideas? The array that I'm trying to return is a list of files in a directory that are in no way referenced in a database.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community