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


PHP Request::json方法代码示例

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


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

示例1: createUser

 public function createUser(Request $request)
 {
     if ($request->isMethod('post')) {
         $user = new User();
         $errors = null;
         $user->firstname = $request->json('firstname');
         $user->lastname = $request->json('lastname');
         $user->email = $request->json('email');
         $user->facebookid = $request->json('facebookid');
         if ($user->firstname === null || $user->lastname === null) {
             $errors .= " no firstname or lastname supplied \n";
         }
         if ($user->facebookid === null) {
             $errors .= " no Facebook ID supplied \n";
         }
         if ($errors === null) {
             try {
                 $user->save();
             } catch (QueryException $e) {
                 //TODO check this is the correct error
                 return "Error, Facebook ID already in use ";
             }
         } else {
             return "Error," . $errors;
         }
         $user->token()->save($this->newToken());
         return json_encode(["userid" => $user->id, "AuthToken" => $user->token->api_token]);
     } else {
         return response('Invalid request', 405)->header('Allow', 'POST');
     }
 }
开发者ID:GoAwayPeter,项目名称:MatchiServer,代码行数:31,代码来源:UserController.php

示例2: store

 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request $request
  *
  * @return \Illuminate\Http\Response
  *
  */
 public function store(Request $request)
 {
     // Read subscriber details
     $uuid = $request->json('uuid');
     $latitude = $request->json('latitude');
     $longitude = $request->json('longitude');
     // Validate latitude/longitude
     if (!is_numeric($latitude)) {
         return response()->json(['message' => "Latitude must be a number."], Response::HTTP_BAD_REQUEST);
     }
     if (!is_numeric($longitude)) {
         return response()->json(['message' => "Longitude must be a number."], Response::HTTP_BAD_REQUEST);
     }
     // Check if user is already subscribed
     $repository = SubscriberRepository::getInstance();
     $subscriber = $repository->getByUuid($uuid);
     if (!empty($subscriber)) {
         return response()->json(['message' => "Already subscribed."], Response::HTTP_BAD_REQUEST);
     }
     $subscriber = new Subscriber();
     $subscriber->setUuid($uuid);
     $subscriber->setLatitude(doubleval($latitude));
     $subscriber->setLongitude(doubleval($longitude));
     try {
         $subscriber->save();
     } catch (QueryException $exception) {
         return response()->json(['message' => "Oops, something went wrong."], Response::HTTP_INTERNAL_SERVER_ERROR);
     }
     return response()->json([], Response::HTTP_CREATED);
 }
开发者ID:NemanjaK,项目名称:meteoalarm,代码行数:38,代码来源:SubscribeController.php

示例3: postReading

 public function postReading(Request $request)
 {
     $therm = Thermostat::where('guid', $request->json('guid'))->first();
     $reading = $therm->readings()->create(array());
     $reading->temperature = $request->json('temperature');
     $reading->humidity = $request->json('humidity');
     $reading->save();
 }
开发者ID:millidavids,项目名称:thermostat-service-laravel,代码行数:8,代码来源:ThermostatController.php

示例4: store

 /**
  * Insert new organizations to the database
  *
  * @param Request $request
  * @param RelationInserter $inserter
  * @return Response
  */
 public function store(Request $request, RelationInserter $inserter)
 {
     // Check for valid / not empty request body
     if (!$request->json()->all()) {
         return response('', 400);
     }
     $inserter->insert($request->json()->all());
     return response('', 201);
 }
开发者ID:anroots,项目名称:dag,代码行数:16,代码来源:OrganizationsController.php

示例5: update

 public function update(Request $req, JsonResponse $res, $id)
 {
     $type = $req->json('data.type');
     $attrs = $req->json('data.attributes');
     $game = $this->game->find($id);
     $game->fill($attrs);
     $game->save();
     return new JsonResponse(['data' => $this->serializeGame($game)]);
 }
开发者ID:EmberGrep,项目名称:game-scores-api,代码行数:9,代码来源:GamesController.php

示例6: calculator

 public function calculator(Request $request, $id)
 {
     $logistics = Logistics::findOrFail($id);
     $package = new Package();
     $items = $request->json()->get('items', []);
     foreach ($items as $index => $item) {
         $package->add($item);
     }
     $package->to($request->json()->get('to'));
     return ['price' => $logistics->deliverer->calc($package)];
 }
开发者ID:kshar1989,项目名称:dianpou,代码行数:11,代码来源:LogisticsController.php

示例7: update

 public function update(Request $request, $id)
 {
     $admin = Admin::findOrFail($id);
     $admin->fill(array_except($request->json()->all(), 'roles'));
     $admin->save();
     if ($roles = array_filter($request->json()->get('roles'))) {
         $admin->roles()->detach();
         if (!empty($roles)) {
             $admin->roles()->attach($roles);
         }
     }
     return response()->updated($admin);
 }
开发者ID:kshar1989,项目名称:dianpou,代码行数:13,代码来源:AdminController.php

示例8: catchNotification

 /**
  * @author WN
  * @param $installation
  * @param Request $request
  * @return \Illuminate\Http\JsonResponse
  */
 public function catchNotification($installation, Request $request)
 {
     try {
         $application = $this->notificationCatcherService->catchNotification($request->json('application'), $installation);
         if ($application->location !== null && $request->json('new_status') == 'converted' && $application->location->converted_email) {
             $this->locationNotificationService->convertedNotification($application, $application->location);
         }
         return response()->json(['local_id' => $application->id, 'current_status' => $application->ext_current_status], 200);
     } catch (\Exception $e) {
         $this->logError('CatchNotification: Failed with message: ' . $e->getMessage());
         return response()->json(['message' => $e->getMessage()], 400);
     }
 }
开发者ID:paybreak,项目名称:basket,代码行数:19,代码来源:NotificationsController.php

示例9: refund

 public function refund(Request $request, $sn)
 {
     $order = $this->resources->where('sn', '=', $sn)->where('user_id', '=', $request->user->id)->firstOrFail();
     if ($order->order_status == Order::STATUS_COMPLETED) {
         \DB::transaction(function () use($sn, $request, $order) {
             $order->refund($request->json()->all())->logs()->save(new OrderLog(['do' => 'refund', 'name' => $request->user->name, 'comment' => $request->json()->get('comment')]));
         });
     } else {
         \DB::transaction(function () use($sn, $request, $order) {
             $order->refundAndCancel($request->json()->get('reason'))->logs()->save(new OrderLog(['do' => 'refund_and_cancel', 'name' => $request->user->name, 'comment' => $request->json()->get('comment')]));
         });
     }
     return response()->updated($order);
 }
开发者ID:kshar1989,项目名称:dianpou,代码行数:14,代码来源:OrderController.php

示例10: submit

 public function submit(Request $request)
 {
     if (!$request->ajax()) {
         throw new MethodNotAllowedHttpException();
     }
     if (!$request->has('contact_data') || !$request->has('test_data')) {
         return response()->json(['result' => 'failure', 'message' => 'Sorry, something went wrong...']);
     }
     $contactData = $request->json('contact_data');
     $testData = $request->json('test_data');
     $quizEntry = new Quiz(['name' => $contactData['name'], 'email' => $contactData['email'], 'telephone' => $contactData['telephone'], 'test_type' => 'new_student', 'answered' => $testData['answered'], 'correct' => $testData['correct'], 'failed' => $testData['failed'], 'level_title' => $testData['level_title']]);
     $quizEntry->save();
     return response()->json(['result' => 'success', 'redirect' => '/quiz/success'])->withCookie(cookie('passed_test_result', $testData['level_title'], 120));
 }
开发者ID:yatsyukv,项目名称:winwin-management,代码行数:14,代码来源:QuizController.php

示例11: create

 /**
  * Creates the site
  *
  * @return Response
  */
 public function create(Request $request)
 {
     // get request
     $name = $request->json()->get('name');
     $theme = $request->json()->get('theme');
     $email = $request->json()->get('email');
     $password = $request->json()->get('password');
     $passcode = $request->json()->get('passcode');
     if ($passcode == env('PASSCODE')) {
         $arr = Site::create($name, $theme, $email, $password);
         return response()->json($arr);
     } else {
         return response('Passcode invalid', 401);
     }
 }
开发者ID:YounessTayer,项目名称:respond,代码行数:20,代码来源:SiteController.php

示例12: postSearchRecipes

 public function postSearchRecipes(Request $request)
 {
     AlbertHeijn::setApiKey(env('API_KEY_ALBERTHEIJN'));
     $products = $request->json()->get('products');
     // Filters
     $filters = array();
     if ($request->json()->has('receptvleesvisofvega')) {
         $filters['receptvleesvisofvega'] = $request->json()->get('receptvleesvisofvega');
     }
     if ($request->json()->has('receptallergeneninfo')) {
         $filters['receptallergeneninfo'] = $request->json()->get('receptallergeneninfo');
     }
     $recipes = AlbertHeijn::searchRecipes($products, $filters);
     return response()->json($recipes);
 }
开发者ID:serioushomebrew,项目名称:receptit,代码行数:15,代码来源:SearchController.php

示例13: updateConductoresEnTurno

 public function updateConductoresEnTurno(Request $request, $ruta_id)
 {
     $noty = new NotificacionController();
     $data = $request->json()->all();
     $turnos_actuales = [];
     $ruta = Ruta::find($ruta_id);
     foreach ($data['turnos'] as $turno) {
         $turnos_actuales[$turno['conductor_id']] = ['turno' => $turno['turno']];
     }
     if ($ruta->toUpdateTurnos()->sync($turnos_actuales)) {
         $ruta = $ruta->destino->ciudad;
         foreach ($data['turnos'] as $turno) {
             if ($request['accion'] == 'agregar') {
                 $mensaje = "Has sido agregado a la ruta hacia {$ruta->nombre} en el turno " . $turno['turno'];
                 $noty->enviarNotificacionConductores($mensaje, $turno['conductor_id'], 'Actualizacion turno', $ruta_id);
             }
             if ($request['accion'] == 'quitar') {
                 $mensaje = "Has sido removido de los turnos de la ruta hacia {$ruta->nombre}";
                 $noty->enviarNotificacionConductores($mensaje, $turno['conductor_id'], 'Actualizacion turno', $ruta_id);
             }
             if ($request['accion'] == 'default') {
                 $mensaje = "Estas en el turno " . $turno['turno'] . " en la ruta hacia {$ruta->nombre}";
                 $noty->enviarNotificacionConductores($mensaje, $turno['conductor_id'], 'Actualizacion turno', $ruta_id);
             }
         }
         return response()->json(['mensaje' => 'turnos modifcados'], 201);
     } else {
         return response()->json(['mensajError' => 'error al actualizar lso turnos'], 400);
     }
 }
开发者ID:andybolano,项目名称:viaja_seguro,代码行数:30,代码来源:RutasController.php

示例14: update

 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     try {
         $data = $request->json()->all();
         unset($data['empresa']);
         unset($data['vehiculo']);
         $conductor = Conductor::find($id);
         if ($conductor) {
             //                actualizo los campos del conductor
             foreach ($data as $campo => $valor) {
                 $conductor->{$campo} = $valor;
             }
             if ($conductor->save()) {
                 if ($request->estado == 'Disponible') {
                     \App::make('\\App\\Events\\UpdatedEstadoConductorEvent')->enviarNotificacion("Notificacion", "El conductor {$conductor->nombres}" . " {$conductor->apellidos} se ha reportado como {$conductor->estado}", $conductor, $conductor->central_id);
                 } else {
                     \App::make('\\App\\Events\\UpdatedEstadoConductorEvent')->enviarNotificacion("Notificacion", "El conductor {$conductor->nombres}" . " {$conductor->apellidos} se ha reportado como {$conductor->estado}", $conductor, $conductor->central_id);
                 }
                 return JsonResponse::create(array('message' => "Actualizado Correctamente"), 200);
             } else {
                 return JsonResponse::create(array('message' => "No se pudo actualizar el registro"), 400);
             }
         } else {
             return response()->json(['mensaje' => 'El conductor no existe'], 400);
         }
     } catch (Exception $e) {
         return JsonResponse::create(array('message' => "Se produjo una exepcion", "exception" => $e->getMessage()), 401);
     }
 }
开发者ID:andybolano,项目名称:viaja_seguro,代码行数:36,代码来源:ConductorController.php

示例15: authenticate

 public function authenticate(Request $request)
 {
     $credentials = $request->json()->all();
     if (!($user = Auth::attempt($credentials, $request->has('remember')))) {
         return false;
     }
     $user = Auth::user();
     $key = config('jwt.key');
     $signer = new Sha256();
     $builder = (new Builder())->setIssuer(config('jwt.host'))->set('uid', $user->id);
     if (config('jwt.payload')['aud']) {
         $builder->setAudience($request->server('REMOTE_ADDR'));
     }
     if (config('jwt.payload')['iss']) {
         $builder->setIssuedAt(time());
     }
     if (config('jwt.payload')['nbf']) {
         $builder->setNotBefore(time() + config('jwt.not_before_time'));
     }
     if (config('jwt.payload')['exp']) {
         $builder->setExpiration(time() + config('jwt.expires'));
     }
     $token = $builder->sign($signer, $key)->getToken();
     return $token->__toString();
 }
开发者ID:brenodouglas,项目名称:laraveljwt,代码行数:25,代码来源:JwtAuth.php


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