DB query builder toArray() laravel 4

前端 未结 7 1273
野性不改
野性不改 2021-02-01 13:32

I\'m trying to convert a query to an array with the method toArray() but it doesn\'t work for the query builder. Any ideas for convert it?

Example



        
相关标签:
7条回答
  • 2021-02-01 14:08

    Easiest way is using laravel toArray function itself:

        $result = array_map(function ($value) {
            return $value instanceof Arrayable ? $value->toArray() : $value;
        }, $result);
    
    0 讨论(0)
提交回复
热议问题