本文整理汇总了PHP中Illuminate\Support\Facades\Request::wantsJson方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::wantsJson方法的具体用法?PHP Request::wantsJson怎么用?PHP Request::wantsJson使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Support\Facades\Request
的用法示例。
在下文中一共展示了Request::wantsJson方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getFormat
/**
* Get Format
*
* Determines which format to use for output.
*/
protected function getFormat()
{
$format = $this->defaultFormat;
if (!Request::wantsJson()) {
$format = Request::format($format);
}
return $format;
}
示例2: getAllStage
/**
* Retourne :
* -l'ensemble des stages(valide, non pourvu et avec competences)
* -l'ensemble des competences
* -l'ensemble des promotions avec specialites
* le tout au format Json si requête Json sinon retourne accueil message erreur
* @return View
*/
public function getAllStage(OffreStageRepository $offreStageRepository, CompetenceRepository $competenceRepository, PromotionRepository $promotionRepository)
{
$array['offres'] = $offreStageRepository->getOffresAPourvoirWithCompetences();
$array['competences'] = $competenceRepository->all();
$array['promotions'] = $promotionRepository->promotionWithSpecialite();
if (Request::wantsJson()) {
return Response::json($array);
} else {
return Redirect::route('accueil-etudiant')->with('flash_error', 'Accès refusée!!!');
}
}
示例3: getAllEtudiant
/**
* Retourne :
* -l'ensemble des etudiants en recherche de stage(recherche == 1)
* -l'ensemble des competences
* -l'ensemble des promotions avec specialites
* le tout au format Json si requête Json sinon retourne accueil message erreur
* @return View
*/
public function getAllEtudiant(EtudiantRepository $etudiantRepository, CompetenceRepository $competenceRepository, PromotionRepository $promotionRepository)
{
$array['etudiants'] = $etudiantRepository->getEtudiantEnRechercheDeStage();
$array['competences'] = $competenceRepository->all();
$array['promotions'] = $promotionRepository->promotionWithSpecialite();
if (Request::wantsJson()) {
return Response::json($array);
} else {
return Redirect::route('accueil-entreprise')->with('flash_error', 'Accès refusée!!!');
}
}
示例4: printPrettyError
/**
* Return a pretty error page when not in debug mode and request doesn't require JSON
*
* @param \Exception $exception
* @param int $code
*
* @return \Illuminate\View\View|void
*/
private function printPrettyError($exception, $code)
{
$showPretty = Config::get('pretty-error-page::always_pretty') === true || Config::get('pretty-error-page::always_pretty') !== false && !Config::get('app.debug');
if ($showPretty && !Request::wantsJson()) {
//Get the corrcet error message from the exception
$message = $exception->getMessage();
$message = !empty($message) ? $message : ($code == 404 ? 'Route not found' : 'An unknown Error occured');
View::share('message', $message);
View::share('exception', $exception);
View::share('code', $code);
return View::make($this->getErrorView($code));
}
}
示例5: validate
/**
* Validate an array of attributes.
*
* @param ParameterBag|array $attributes
* @param callable|null $callback
*
* @throws ValidationException
*
* @return mixed
*/
public function validate($attributes = [], callable $callback = null)
{
// Unwrap parameter bags
if ($attributes instanceof ParameterBag) {
$attributes = $attributes->all();
}
// Get attributes and create Validator
$validation = $this->validator->make($attributes, $this->getRules($attributes), $this->getMessages());
// Alter rules and stuff
$validation = $this->alterValidation($validation);
if ($validation->fails()) {
$exception = ValidationException::class;
if (class_exists('Dingo\\Api\\Exception\\ResourceException') && (Request::wantsJson() || Request::isJson())) {
$exception = ResourceException::class;
}
throw new $exception('Validation failed', $validation->getMessageBag());
} elseif ($callback) {
return $callback($attributes, $this->model);
}
return true;
}
示例6: filter
/**
* Main method, if 'successful' this method should not return anything (even true).
*
* @param $request
* @return \Illuminate\Http\RedirectResponse
* @throws Exception
*/
public function filter($request)
{
// Check if user is authenticated via an auth session
$this->session_authenticated = $this->isUserSessionAuthenticated();
// Check if user is authenticated via an auth token
$this->token_authenticated = $this->isUserTokenAuthenticated($request);
// Decide if user is authenticated
$this->user_authenticated = $this->isUserAuthenticated([$this->session_authenticated, $this->token_authenticated]);
if ($this->user_authenticated === false) {
// There is no way to know, for definite, which 'method' a user intended to authenticate, unless a token was
// used, in which case it is safe to assume which method they were using.
// In cases where a token wasn't given and the user has requested a JSON response, we assume they were trying
// to use token authentication. Otherwise we assume they were trying to use session authentication.
// Note: This approach maybe revised in the future.
if ($this->token_authenticated !== false && $this->token_authenticated instanceof MissingTokenException === false || Request::wantsJson()) {
$this->tokenAuthenticationFailure();
}
$this->sessionAuthenticationFailure();
// BUG: For some reason issuing a redirect within a function other than this one doesn't do anything.
return Redirect::guest('login');
}
}
示例7: push
/**
* Push responses to user agent (browser or external app)
*
* @param array $data Response dasta
* @return mixed Response::json() or Redirect::to()
* @static
*/
public static function push($data = array())
{
$headers = isset($data['headers']) ? $data['headers'] : array();
$secure = isset($data['secure']) ? $data['secure'] : NULL;
$options = isset($data['options']) ? $data['options'] : NULL;
$input = isset($data['input']) ? TRUE : FALSE;
if (Request::ajax() or Request::isJson() or Request::wantsJson()) {
$status = '200';
return Response::json($data, $status, $headers, $options);
} else {
$status = '302';
$response = Redirect::to($data['path'], $status, $headers, $secure);
if (isset($data['errors'])) {
$response->withErrors($data['errors']);
}
if (isset($data['messages'])) {
$response->with($data['messages']);
}
if ($input) {
$response->withInput();
}
return $response;
}
}
示例8: __return
/**
* Return a response either view or json.
*
* @param string $status
* @param string $message
* @param obj|array $data
* @param integer $statusCode
* @param string $viewName
* @param array $headers
* @param string $callback
*
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\Response|\Illuminate\Routing\ResponseFactory
*/
private function __return($status, $message, $data, $statusCode = 200, $viewName = 'data', $headers = [], $callback = 'callback')
{
if (Request::ajax() || Request::wantsJson() || Request::isJson() || Request::acceptsJson()) {
return $this->responseInJson($status, $message, $data, $statusCode, $headers, $callback);
}
return $this->responseInView(collect(['message' => $message, 'data' => $data]), $viewName);
}
示例9: userExists
public function userExists($id = null, $key = null, $value = null)
{
$exists = false;
$id || ($id = Input::get("search_id"));
$key || ($key = Input::get("search_key"));
$value || ($value = Input::get("search_value"));
$user = UserItem::alreadyExistingItem($key, $value);
if ($user) {
if (!$id || $id && $id != $user->id) {
$exists = true;
}
}
if (Request::wantsJson()) {
return Response::json(array('valid' => !$exists));
}
return $exists;
}
示例10: permissionExists
public function permissionExists($id = null, $value = null)
{
$exists = false;
$id || ($id = Input::get("search_id"));
$value || ($value = Input::get("search_value"));
$permission = PermissionItem::alreadyExistingItem("permission_key", $value);
if ($permission) {
if (!$id || $id && $id != $permission->id) {
$exists = true;
}
}
if (Request::wantsJson()) {
return Response::json(array('valid' => !$exists));
}
return $exists;
}