php - Specific json formatting return from Laravel Eloquent model -
i trying format data tags contained in laravel 4 model tag:
id - integer tag - string
simple stuff. have route set up:
route::get('data/tags', function() { $tags = tag::all(); return $tags; }
so returns json in following format:
[{"id":"1","tag":"tag1"},{"id":"2","tag":"tag2"}]
the problem is, trying make json work twitter typeahead.js
library and, according docs there, needs like:
{ value: '@jakeharding', tokens: ['jake', 'harding'] }
using data, believe mean (but may wrong here):
{ value: '@tags', tokens: ['tag1', 'tag2'] }
so query is, how make output json laravel 4 match json format needed typeahead.js?
you loop $tags , create new array info on format need. return new array (laravel handle conversion json)
Comments
Post a Comment