當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。