How to remove index number from laravel eloquent unique

后端 未结 2 1791
北恋
北恋 2021-01-15 05:31

I am using a query that returns value perfectly but it adds key number to the collection. How can I remove the index number?

Here is the retrieved data



        
相关标签:
2条回答
  • 2021-01-15 05:38

    You have to do it manually

       $users=\App\User::get()->toArray(); // your query here 
       $data['data']=[];
       foreach($users as $user ){ 
             $data['data'][]=$user; 
        }
       $k=json_encode($data); dd($k);
    
    0 讨论(0)
  • 2021-01-15 05:52

    In order to get a collection without a index you have to add the "values" method

    $collection->unique('id')->values();
    
    0 讨论(0)
提交回复
热议问题