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


PHP Request::ajax方法代码示例

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


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

示例1: render

 /**
  * Render an exception into an HTTP response.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Exception  $e
  * @return \Illuminate\Http\Response
  */
 public function render($request, Exception $e)
 {
     // 404 page when a model is not found
     if ($e instanceof ModelNotFoundException) {
         if ($request->ajax() || $request->wantsJson()) {
             return response()->json(['error' => 404, 'mensaje' => 'Recurso no encontrado'], 404);
         }
         return response()->view('errors.404', [], 404);
     }
     if ($this->isHttpException($e)) {
         if ($request->ajax() || $request->wantsJson()) {
             return response()->json(['error' => 404, 'mensaje' => 'Recurso no encontrado!'], 404);
         }
         return $this->renderHttpException($e);
     } else {
         // Custom error 500 view on production
         if (app()->environment() == 'production') {
             if ($request->ajax() || $request->wantsJson()) {
                 return response()->json(['error' => ['exception' => class_basename($e) . ' in ' . basename($e->getFile()) . ' line ' . $e->getLine() . ': ' . $e->getMessage()]], 500);
             }
             return response()->view('errors.500', [], 500);
         }
         return parent::render($request, $e);
     }
 }
开发者ID:Nemeziz,项目名称:inegi,代码行数:32,代码来源:Handler.php

示例2: handle

 /**
  * Handle an incoming request.
  *
  * @param \Illuminate\Http\Request $request
  * @param \Closure                 $next
  *
  * @return mixed
  */
 public function handle($request, Closure $next, $role, $guard = null)
 {
     if (Auth::guard($guard)->guest()) {
         if ($request->ajax() || $request->wantsJson()) {
             return response('Unauthorized.', 401);
         } else {
             return redirect()->guest('login');
         }
     }
     if (user($guard)->new && config('user.verify_email')) {
         if ($request->ajax() || $request->wantsJson()) {
             return response('Unauthorized.', 401);
         } else {
             return redirect('verify');
         }
     }
     if (!user($guard)->active && config('user.verify_email')) {
         throw new InvalidAccountException('Account is not active.');
     }
     $roles = explode('|', $role);
     if (!user($guard)->hasRoles($roles)) {
         throw new RolesDeniedException($roles);
     }
     return $next($request);
 }
开发者ID:LavaLite,项目名称:framework,代码行数:33,代码来源:VerifyRole.php

示例3: store

 public function store(Request $request)
 {
     $user = Sentinel::getUser();
     if ($user->id !== intval($request->uid)) {
         $rules = ['uid' => 'required|numeric|exists:users,id|min:1', 'score' => 'required|numeric'];
         $validator = Validator::make($request->all(), $rules);
         if ($validator->fails()) {
             if ($request->ajax()) {
                 return response()->json(['result' => false]);
             } else {
                 return back()->withInput()->withErrors($validator);
             }
         } else {
             # Create Resume
             $rate = new Rate();
             $rate->score = intval($request->score);
             $rate->to_user_id = intval($request->uid);
             # Redirect on Success
             if ($user->rates()->save($rate)) {
                 if ($request->ajax()) {
                     $userprofile = Sentinel::findById($rate->to_user_id);
                     return response()->json(['result' => false, 'score' => $userprofile->profileRates()->avg('score')]);
                 } else {
                     return redirect()->route('user.show', ['user' => $rate->to_user_id])->with('success', 'امتیاز شما با موفقیت ثبت شد.');
                 }
             }
         }
     }
     if ($request->ajax()) {
         return response()->json(['result' => false]);
     } else {
         return back()->withInput()->with('fail', 'مشکل در اتصال به سرور. لطفا مجددا تلاش کنید.');
     }
 }
开发者ID:majid-n,项目名称:cometdev,代码行数:34,代码来源:RateController.php

示例4: handle

 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     if ($this->auth->guest()) {
         if ($request->ajax()) {
             return response('Unauthorized.', 401);
         } else {
             return redirect()->route('auth.signin');
         }
     } else {
         $user = $this->auth->user();
         if ($user->ban) {
             if ($request->ajax()) {
                 return response('Unauthorized.', 401);
             } else {
                 $this->auth->logout();
                 notify()->flash('Banned', 'error', ['text' => $user->ban_reason]);
                 return redirect()->route('auth.signin');
             }
         }
     }
     /*$ipInfo = getIpInfo($request->getClientIp());
       if($ipInfo){
           if(isset($ipInfo['timezone'])){
               if($ipInfo['timezone'] != $this->auth->user()->timezone){
                   $this->auth->user()->update([
                       'timezone' => $ipInfo['timezone']
                   ]);
               }
           }
       }*/
     return $next($request);
 }
开发者ID:vuonghuuphuc,项目名称:coder,代码行数:39,代码来源:Authenticate.php

示例5: handle

 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request $request
  * @param  \Closure $next
  * @param  string $role
  * @return mixed
  */
 public function handle($request, Closure $next, $role)
 {
     switch ($role) {
         case 'admin':
             if (!$request->user()->is_admin) {
                 if ($request->ajax()) {
                     return response('Access Denied')->setStatusCode(403);
                 }
                 abort(404);
             }
             break;
         case 'moderator':
             if (!$request->user()->is_moderator) {
                 if ($request->ajax()) {
                     return response('Access Denied')->setStatusCode(403);
                 }
                 abort(404);
             }
             break;
         default:
             return response('Access Denied')->setStatusCode(403);
             break;
     }
     return $next($request);
 }
开发者ID:Kadexi,项目名称:CSGOVoid,代码行数:33,代码来源:Access.php

示例6: anyUpload

 public function anyUpload(InterfaceFileStorage $userFileStorage, AmqpWrapper $amqpWrapper, Server $server, UploadEntity $uploadEntity)
 {
     /* @var \App\Components\UserFileStorage $userFileStorage */
     $responseVariables = ['uploadStatus' => false, 'storageErrors' => [], 'uploadEntities' => []];
     if ($this->request->isMethod('post') && $this->request->hasFile('file') && $this->request->file('file')->isValid()) {
         $tmpDir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'tmp-user-files-to-storage' . DIRECTORY_SEPARATOR;
         $tmpFilePath = $tmpDir . $this->request->file('file')->getClientOriginalName();
         $this->request->file('file')->move($tmpDir, $this->request->file('file')->getClientOriginalName());
         $userFileStorage->setValidationRules($this->config->get('storage.userfile.validation'));
         $newStorageFile = $userFileStorage->addFile($tmpFilePath);
         if ($newStorageFile && !$userFileStorage->hasErrors()) {
             /* @var \SplFileInfo $newStorageFile */
             // AMQP send $newfile, to servers
             foreach ($server->all() as $server) {
                 if (count($server->configs) > 0) {
                     foreach ($server->configs as $config) {
                         // Send server and file info to upload queue task
                         $amqpWrapper->sendMessage($this->config->get('amqp.queues.uploader.upload'), json_encode(['file' => $newStorageFile->getRealPath(), 'url' => $server->scheme . '://' . $config->auth . '@' . $server->host . '/' . trim($config->path, '\\/')]));
                     }
                 } else {
                     // The server has no configuration
                     $amqpWrapper->sendMessage($this->config->get('amqp.queues.uploader.upload'), json_encode(['file' => $newStorageFile->getRealPath(), 'url' => $server->scheme . '://' . $server->host]));
                 }
             }
             $responseVariables['uploadStatus'] = true;
         } else {
             $responseVariables['storageErrors'] = $userFileStorage->getErrors();
         }
         if ($this->request->ajax()) {
             return $this->response->json($responseVariables);
         }
     }
     $responseVariables['uploadEntities'] = $uploadEntity->limit(self::UPLOAD_ENTITIES_LIMIT)->orderBy('created_at', 'DESC')->get();
     return $this->view->make('upload.index', $responseVariables);
 }
开发者ID:ysaroka,项目名称:uploader,代码行数:35,代码来源:UploadController.php

示例7: handle

 /**
  * Handle an incoming request.
  *
  * @param \Illuminate\Http\Request $request
  * @param \Closure                 $next
  *
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     // If the user isn't logged in or they are part of a different city
     // deny access, otherwise go for it. Might be worth adding a message to
     // explain what happened on redirect.
     $city = City::findByIATA($request->route()->getParameter('city'))->first();
     if ($this->auth->guest()) {
         if ($request->ajax()) {
             return response('Unauthorized.', 401);
         } else {
             Notification::error('You need to be logged in to view that.');
             return redirect()->guest('auth/login');
         }
     } else {
         if ($city && $this->auth->user()->city_id !== $city->id) {
             Notification::error('You don\'t have permissions for that city.');
             if ($request->ajax()) {
                 return response('Unauthorized.', 401);
             } else {
                 return redirect('/' . $city->iata);
             }
         }
     }
     return $next($request);
 }
开发者ID:EMT,项目名称:see-do,代码行数:33,代码来源:Authenticate.php

示例8: addAddress

 public function addAddress(Request $request)
 {
     $user = Sentinel::getUser();
     $rules = ['address' => 'min:10'];
     $validator = Validator::make($request->all(), $rules);
     $result = 2;
     $id = 'address' . $result;
     if ($validator->fails()) {
         if ($request->ajax()) {
             return response()->json(['result' => false]);
         } else {
             return back()->withInput()->withErrors($validator);
         }
     }
     if (!$user->address2) {
         $user->address2 = $request->input('new');
     } else {
         $user->address3 = $request->input('new');
         $result = 3;
         $id = 'address' . $result;
     }
     if ($user->save()) {
         if ($request->ajax()) {
             return response()->json(['result' => $user->{$id}, 'aid' => $result]);
         } else {
             return back()->with('success', 'آدرس جدید اضافه شد.');
         }
     }
 }
开发者ID:majid-n,项目名称:printkala,代码行数:29,代码来源:HomeController.php

示例9: handle

 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $siteID = $request->route('sites');
     $site = \App\Models\Site::find($siteID);
     // normal and admin users accessing other site info
     if (\Auth::user()->super == "No") {
         if (\Auth::user()->site_id != $siteID) {
             if ($request->ajax()) {
                 return response('Unauthorized', 401);
             } else {
                 return redirect()->guest('noAccess');
             }
         }
     }
     // if super user is trying to access a site belonging to another company
     if (\Auth::user()->super == "Yes") {
         if (\Auth::user()->site->company_id != $site->company_id) {
             if ($request->ajax()) {
                 return response('Unauthorized', 401);
             } else {
                 return redirect()->guest('noAccess');
             }
         }
     }
     return $next($request);
 }
开发者ID:leanne-abarro,项目名称:tagAndTrack,代码行数:33,代码来源:SiteFilter.php

示例10: handle

 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     if ($this->auth->guest()) {
         if ($request->ajax()) {
             return response('Unauthorized.', 403);
         } else {
             return redirect()->guest('auth/login');
         }
     }
     if (!$request->user()->isAdmin() && $request->user()->cannot('dashboard_view')) {
         $this->auth->logout();
         return redirect()->guest('auth/login')->withErrors(trans('messages.permission_denied'));
     }
     $route_array = explode('.', $request->route()->getName());
     $permission_name = array_search($route_array[2], array_dot($this->permission_fields));
     if ($permission_name) {
         $route_array[2] = explode('.', $permission_name)[0];
     }
     // $route_name = implode('_', $route_array);
     $route_name = $route_array[1] . '_' . $route_array[2];
     if (!$request->user()->isAdmin() && $request->user()->cannot($route_name)) {
         //PATCH 为null
         if ($request->ajax()) {
             return response()->json(['status' => trans('messages.permission_denied'), 'type' => 'error', 'code' => 403]);
         } else {
             return view('errors.403');
         }
     }
     return $next($request);
 }
开发者ID:hramose,项目名称:laravel-5-admin,代码行数:37,代码来源:Authenticate.php

示例11: handle

 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     // First make sure there is an active session
     // dd(debug_print_backtrace(2));
     // dd(Sentry::check());
     if (!Sentry::check()) {
         if ($request->ajax()) {
             return response('Unauthorized.', 401);
         } else {
             return redirect()->guest(route('sentinel.login'));
         }
     }
     // Now check to see if the current user has the 'admin' permission
     // dd(get_class(Sentry::getUser()));
     // dd(Sentry::getUser()->hasAccess('admin'));//Sentinel\Models\User
     if (!Sentry::getUser()->hasAccess('admin')) {
         if ($request->ajax()) {
             return response('Unauthorized.', 401);
         } else {
             Session::flash('error', trans('Sentinel::users.noaccess'));
             return redirect()->route('sentinel.login');
         }
     }
     // dd(Sentry::getUser()->hasAccess('admin'));
     // dd(Sentry::getId());
     // dd(Sentry::getGroups());
     // All clear - we are good to move forward
     return $next($request);
 }
开发者ID:acmadi,项目名称:integrasi,代码行数:36,代码来源:SentryAdminAccess+Backup+.php

示例12: item

 /**
  * Gets the item edit page / information
  *
  * @param string		$modelName
  * @param mixed			$itemId
  */
 public function item($modelName, $itemId = 0)
 {
     $config = app('itemconfig');
     $fieldFactory = app('admin_field_factory');
     $actionFactory = app('admin_action_factory');
     $columnFactory = app('admin_column_factory');
     $actionPermissions = $actionFactory->getActionPermissions();
     $fields = $fieldFactory->getEditFields();
     //if it's ajax, we just return the item information as json
     if ($this->request->ajax()) {
         //try to get the object
         $model = $config->getModel($itemId, $fields, $columnFactory->getIncludedColumns($fields));
         if ($model->exists) {
             $model = $config->updateModel($model, $fieldFactory, $actionFactory);
         }
         $response = $actionPermissions['view'] ? response()->json($model) : response()->json(array('success' => false, 'errors' => "You do not have permission to view this item"));
         //set the Vary : Accept header to avoid the browser caching the json response
         return $response->header('Vary', 'Accept');
     } else {
         $view = view("administrator::index", array('itemId' => $itemId));
         //set the layout content and title
         $this->layout->content = $view;
         return $this->layout;
     }
 }
开发者ID:nanosolutions,项目名称:Laravel-Administrator,代码行数:31,代码来源:AdminController.php

示例13: getIndex

 /**
  * Show the login form
  *
  * @return mixed
  */
 public function getIndex()
 {
     if ($this->request->ajax()) {
         $this->session->forget('url.intended');
     }
     return View::make('auth.login');
 }
开发者ID:jraymundoyrockdev,项目名称:api-gfccm-systems,代码行数:12,代码来源:AuthController.php

示例14: girls

 /**
  * @param User $modelUser
  * @return \Illuminate\Http\JsonResponse|\Illuminate\View\View
  */
 public function girls(User $modelUser)
 {
     $registered = $modelUser->getGirls();
     if ($this->request->ajax()) {
         return response()->json(view('inc_users', ['registered' => $registered, 'message' => 'Всего зарегистрировано девушек'])->render());
     }
     return view('registered', ['registered' => $registered, 'message' => 'Всего зарегистрировано девушек']);
 }
开发者ID:Colls,项目名称:meetings.laravel,代码行数:12,代码来源:PageController.php

示例15: __construct

 /**
  * __construct.
  *
  * @method __construct
  *
  * @param  array                                        $config
  * @param  \Illuminate\Http\Request                     $request
  * @param  \Illuminate\Contracts\Foundation\Application $app
  */
 public function __construct($config, Request $request = null, Application $app = null)
 {
     $this->request = is_null($request) === true ? Request::capture() : $request;
     $this->ajax = $this->request->ajax();
     $this->app = $app;
     $this->accepts = Arr::get($config, 'accepts', []);
     $this->showBar = Arr::get($config, 'showBar', false);
     $this->initializeTracyDebuger($config);
     $this->loadPanels($config);
 }
开发者ID:recca0120,项目名称:laravel-tracy,代码行数:19,代码来源:Debugbar.php


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