Illuminate\Support\Collection::toJson PHP Method

toJson() public method

Get the collection of items as JSON.
public toJson ( integer $options ) : string
$options integer
return string
    public function toJson($options = 0)
    {
        return json_encode($this->jsonSerialize(), $options);
    }

Usage Example

Exemplo n.º 1
0
 /**
  * Store collection
  * @param Collection $collection
  */
 private function storeCollection(Collection $collection)
 {
     Cache::flush($this->getCacheQuequeMask());
     if (config('lauser.save_type') == 'file') {
         $path = $this->getLaUserFilePathById($this->id);
         Storage::put($path, $collection->toJson());
     } else {
         $isExists = DB::table(config('lauser.save_table'))->where('user_id', $this->id)->count();
         if ($isExists > 0) {
             DB::table(config('lauser.save_table'))->where('user_id', $this->id)->update(['json' => $collection->toJson()]);
         } else {
             DB::table(config('lauser.save_table'))->insert(['user_id' => $this->id, 'json' => $collection->toJson()]);
         }
     }
 }
All Usage Examples Of Illuminate\Support\Collection::toJson