当前位置: 首页>>代码示例>>PHP>>正文


PHP Collection::toJson方法代码示例

本文整理汇总了PHP中Illuminate\Support\Collection::toJson方法的典型用法代码示例。如果您正苦于以下问题:PHP Collection::toJson方法的具体用法?PHP Collection::toJson怎么用?PHP Collection::toJson使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Illuminate\Support\Collection的用法示例。


在下文中一共展示了Collection::toJson方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: storeCollection

 /**
  * 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()]);
         }
     }
 }
开发者ID:pahomovv,项目名称:lauser,代码行数:19,代码来源:LaUserDataAttributesTrait.php

示例2: save

 /**
  * Save the manifest.
  *
  * @return bool
  */
 public function save()
 {
     if ($this->dirty) {
         $path = $this->manifestPath . '/collections.json';
         $this->dirty = false;
         return (bool) $this->files->put($path, $this->entries->toJson());
     }
     return false;
 }
开发者ID:etrepat,项目名称:basset,代码行数:14,代码来源:Manifest.php

示例3: getJson

 /**
  *  Get JSON representation of the data
  * 
  * @return string
  */
 public function getJson($format = 'column')
 {
     switch ($format) {
         case 'column':
             return $json = $this->toJson();
             break;
         default:
             $collection = new Collection($this->getRows());
             return $json = $collection->toJson();
             break;
     }
 }
开发者ID:mechanicious,项目名称:tableman,代码行数:17,代码来源:Tableman.php

示例4: getUploadedFiles

 public function getUploadedFiles()
 {
     if (!File::isDirectory($this->baseDir)) {
         return '[]';
     }
     $return = new Collection();
     foreach (File::files($this->baseDir) as $path) {
         $f = new stdClass();
         $f->name = $this->getFileFullName($path);
         $f->size = File::size($path);
         $return->push($f);
     }
     return $return->toJson();
 }
开发者ID:jakjr,项目名称:dropzone,代码行数:14,代码来源:Dropzone.php

示例5: store

 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     //
     $this->validate($request, ['name_en' => 'required|max:500', 'name_jp' => 'required|max:500', 'description' => 'required|max:5000', 'year_start' => 'required|date_format:Y', 'year_end' => 'required|date_format:Y', 'artwork' => 'required|image', 'age_rating' => 'required|In:1,7,10,12.13.14.17,18']);
     $name_en = $request->input("name_en");
     $name_jp = $request->input("name_jp");
     $description = $request->input("description");
     $age_rating = $request->input("age_rating");
     $year_start = new Carbon();
     $year_end = new Carbon();
     $year_start->year = $request->input("year_start");
     $year_end->year = $request->input("year_end");
     $series = Series::create(["name_en" => $name_en, "name_jp" => $name_jp, "description" => $description, "year_start" => $year_start, "year_end" => $year_end, "age_rating" => $age_rating]);
     $new_filename = uniqid() . "." . $request->file('artwork')->guessExtension();
     $request->file('artwork')->move("artwork/series/" . $series->id . "/", $new_filename);
     $series_artwork = new Collection();
     $series_artwork->push(url("artwork/series/" . $series->id . "/" . $new_filename));
     $series->artwork = $series_artwork->toJson();
     $series->save();
     return redirect("/series");
 }
开发者ID:kcattakcaz,项目名称:malon,代码行数:27,代码来源:SeriesController.php

示例6: toJson

 public function toJson()
 {
     return $this->events->toJson();
 }
开发者ID:antoniobec,项目名称:palencia,代码行数:4,代码来源:EventCollection.php

示例7: jti

 /**
  * Get a unique id (jti) for the token.
  *
  * @return string
  */
 protected function jti()
 {
     return md5(sprintf('%s.%s', $this->claims->toJson(), Str::quickRandom()));
 }
开发者ID:a161527,项目名称:cs319-p2t5,代码行数:9,代码来源:Factory.php

示例8: store

 public function store(Request $request, FormDefinition $formDef)
 {
     $this->validate($request, ['name' => 'required|max:255|string', 'email' => 'required|email']);
     $fields = new Collection();
     $errors = new Collection();
     $request->session()->forget('field_validation_errors');
     $request->session()->put('field_validation_errors', []);
     if ($formDef->submissions()->where('email', $request->input('email'))->get()->count() > 0) {
         $errors->push("A submission already exists for the e-mail you used: " . $request->input("email"));
     }
     foreach ($formDef->fields()->get() as $field) {
         $options = json_decode($field->options);
         if ($options->required && !$request->has($field->field_id) && ($field->type != 'Checkbox' && $field->type != 'File')) {
             $errors->push("Missing required field named " . $field->name . " with ID " . $field->field_id);
         } elseif ($options->required && $field->type == "File" && !$request->hasFile($field->field_id)) {
             $errors->push("Missing required file field named " . $field->name . " with ID " . $field->field_id);
         } elseif (!$request->has($field->field_id) && $field->type != 'File') {
             $fields->put($field->field_id, null);
         } else {
             if ($this->verifyField($field, $request->input($field->field_id), $request)) {
                 if ($field->type != 'File') {
                     $fields->put($field->field_id, $request->input($field->field_id));
                 } else {
                     $fname = "file_" . str_random(32) . "." . $request->file($field->field_id)->getClientOriginalExtension();
                     $file = $request->file($field->field_id)->move('../storage/app/form/' . $formDef->id, $fname);
                     $fields->put($field->field_id, $fname);
                 }
             } else {
                 $errors->push("Invalid value for field named \"" . $field->name . "\" with ID  " . $field->field_id);
             }
         }
     }
     if ($errors->count() > 0) {
         //return response()->json(["The submission was REJECTED and errors follow",$errors],422);
         return redirect()->back()->withErrors($errors);
         //return view('formdefinitions.display', compact('fields', 'errors'));
     }
     $request->session()->forget('form_validation_errors');
     $submission = new Submission(["form_definition_id" => $formDef->id, "name" => $request->input('name'), "email" => $request->input('email'), "password" => null, "submitted" => Carbon::now(), "status" => 'Reviewing', "options" => $fields->toJson()]);
     $submission->save();
     //return response()->json(["The submission was accepted and follows",$submission],200);
     return view('formdefinitions.accepted', compact('formDef', 'submission'));
 }
开发者ID:kcattakcaz,项目名称:CALwebtool,代码行数:43,代码来源:SubmissionController.php

示例9: describeCollection

 /**
  * Describe a Collection.
  *
  * @param Collection $object
  * @param array      $options
  *
  * @return string
  */
 protected function describeCollection(Collection $object, array $options = [])
 {
     return $object->toJson();
 }
开发者ID:anahkiasen,项目名称:janitor,代码行数:12,代码来源:JsonDescriptor.php

示例10: update

 public function update(FormDefinition $form, Request $request)
 {
     if ($form->status != "Drafting" || $form->submissions()->get()->count() > 0) {
         return response()->json(["error" => true, "message" => ["You cannot edit a form that isn't a Draft or has submissions"]], 405);
     } else {
         $this->validate($request, ['name' => 'required|max:100', 'description' => 'required', 'definition' => 'required|array']);
         $fieldErrors = new Collection();
         $old_fields = $form->fields()->get();
         $new_fields = new Collection();
         $formDef = $form;
         $formDef->name = $request->input("name");
         $formDef->description = $request->input('description');
         foreach ($request->input('definition') as $fieldArray) {
             $fieldDef = collect($fieldArray);
             $type = $fieldDef->get("type");
             if ($type == "Text") {
                 $validator = Validator::make($fieldArray, ['id' => 'required|alpha_dash', 'name' => 'required', 'required' => 'required|boolean', 'text_type' => 'required|in:any,num,alpha,email,phone,date,time,multiline']);
                 if ($validator->fails()) {
                     $fieldErrors->push($validator->errors());
                 } else {
                     $field_options = new Collection();
                     $field_options->put('required', $fieldDef->get('required'));
                     $field_options->put('text_type', $fieldDef->get('text_type'));
                     $field = new Field(['form_definition_id' => $formDef->id, 'type' => $fieldDef->get('type'), 'field_id' => $fieldDef->get('id'), 'name' => $fieldDef->get('name'), 'order' => 0, 'options' => $field_options->toJson()]);
                     $field->save();
                 }
             } else {
                 if ($type == "Checkbox") {
                     $validator = Validator::make($fieldArray, ['id' => 'required|alpha_dash', 'name' => 'required', 'required' => 'required', 'value_checked' => 'required', 'value_unchecked' => 'required']);
                     if ($validator->fails()) {
                         $fieldErrors->push($validator->errors());
                     } else {
                         $field_options = new Collection();
                         $field_options->put('required', $fieldDef->get('required'));
                         $field_options->put('value_unchecked', $fieldDef->get('value_unchecked'));
                         $field_options->put('value_checked', $fieldDef->get('value_checked'));
                         $field = new Field(['form_definition_id' => $formDef->id, 'type' => $fieldDef->get('type'), 'field_id' => $fieldDef->get('id'), 'name' => $fieldDef->get('name'), 'order' => 0, 'options' => $field_options->toJson()]);
                         $field->save();
                     }
                 } else {
                     if ($type == "Select") {
                         $validator = Validator::make($fieldArray, ['id' => 'required|alpha_dash', 'name' => 'required', 'required' => 'required', 'multipleselect' => 'required|boolean', 'options' => 'required|array', 'options.*.label' => 'required', 'options.*.value' => 'required']);
                         if ($validator->fails()) {
                             $fieldErrors->push($validator->errors());
                         } else {
                             $field_options = new Collection();
                             $field_options->put('required', $fieldDef->get('required'));
                             $field_options->put('multipleselect', $fieldDef->get('multipleselect'));
                             $field_options->put('options', $fieldDef->get('options'));
                             $field = new Field(['form_definition_id' => $formDef->id, 'type' => $fieldDef->get('type'), 'field_id' => $fieldDef->get('id'), 'name' => $fieldDef->get('name'), 'order' => 0, 'options' => $field_options->toJson()]);
                             $field->save();
                         }
                     } else {
                         if ($type == "RadioGroup") {
                             $validator = Validator::make($fieldArray, ['id' => 'required|alpha_dash', 'name' => 'required', 'required' => 'required', 'options' => 'required|array', 'options.*.label' => 'required', 'options.*.value' => 'required']);
                             if ($validator->fails()) {
                                 $fieldErrors->push($validator->errors());
                             } else {
                                 $field_options = new Collection();
                                 $field_options->put('required', $fieldDef->get('required'));
                                 $field_options->put('options', $fieldDef->get('options'));
                                 $field = new Field(['form_definition_id' => $formDef->id, 'type' => $fieldDef->get('type'), 'field_id' => $fieldDef->get('id'), 'name' => $fieldDef->get('name'), 'order' => 0, 'options' => $field_options->toJson()]);
                                 $field->save();
                             }
                         } else {
                             if ($type == "Address") {
                                 $validator = Validator::make($fieldArray, ['id' => 'required|alpha_dash', 'name' => 'required', 'required' => 'required']);
                                 if ($validator->fails()) {
                                     $fieldErrors->push($validator->errors());
                                 } else {
                                     $field_options = new Collection();
                                     $field_options->put('required', $fieldDef->get('required'));
                                     $field_options->put('options', $fieldDef->get('options'));
                                     $field = new Field(['form_definition_id' => $formDef->id, 'type' => $fieldDef->get('type'), 'field_id' => $fieldDef->get('id'), 'name' => $fieldDef->get('name'), 'order' => 0, 'options' => $field_options->toJson()]);
                                     $field->save();
                                 }
                             } else {
                                 if ($type == "File") {
                                     $validator = Validator::make($fieldArray, ['id' => 'required|alpha_dash', 'name' => 'required', 'required' => 'required']);
                                     if ($validator->fails()) {
                                         $fieldErrors->push($validator->errors());
                                     } else {
                                         $field_options = new Collection();
                                         $field_options->put('required', $fieldDef->get('required'));
                                         $field_options->put('types', $fieldDef->get('types'));
                                         $field = new Field(['form_definition_id' => $formDef->id, 'type' => $fieldDef->get('type'), 'field_id' => $fieldDef->get('id'), 'name' => $fieldDef->get('name'), 'order' => 0, 'options' => $field_options->toJson()]);
                                         $field->save();
                                     }
                                 } else {
                                     $fieldErrors->push(["Unknown field type in submission"]);
                                     continue;
                                 }
                             }
                         }
                     }
                 }
             }
             $new_fields->push($field);
         }
         if ($fieldErrors->count() == 0) {
//.........这里部分代码省略.........
开发者ID:kcattakcaz,项目名称:CALwebtool,代码行数:101,代码来源:FormDefinitionController.php

示例11: castChanges

 /**
  * Cast the changes collection to the appropiate type.
  *
  * @param  Collection $changes
  * @param  Model      $adjustment
  * @return mixed
  */
 protected function castChanges(Collection $changes, Model $adjustment)
 {
     $cast = $adjustment->hasCast(config('adjuster.changes_column'));
     switch ($cast) {
         case 'collection':
             return $changes;
         case 'array':
         case 'json':
             return $changes->toArray();
         default:
             return $changes->toJson();
     }
 }
开发者ID:mangopixel,项目名称:laravel-adjuster,代码行数:20,代码来源:CanBeAdjusted.php


注:本文中的Illuminate\Support\Collection::toJson方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。