本文整理汇总了PHP中Illuminate\Http\Request::isXmlHttpRequest方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::isXmlHttpRequest方法的具体用法?PHP Request::isXmlHttpRequest怎么用?PHP Request::isXmlHttpRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Http\Request
的用法示例。
在下文中一共展示了Request::isXmlHttpRequest方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: deleteMessage
public function deleteMessage(Request $request, Message $message)
{
$result = $message->delete();
if ($result) {
if ($request->isXmlHttpRequest()) {
return ['success' => true];
}
Flash::info('Message ' . $message->id . ' removed.');
return redirect()->back();
}
if ($request->isXmlHttpRequest()) {
return ['success' => false, 'message' => 'Can\'t remove message ' . $message->id];
}
return redirect()->back()->withErrors(['Can\'t remove message ' . $message->id]);
}
示例2: getTownAutoComplete
/**
* @description: get town array with deleting duplicate entries
* @return json array
*/
public function getTownAutoComplete(Request $request)
{
if ($request->isXmlHttpRequest()) {
// set url of data grand Lyon
$json_url = "database/market.json";
// get contents of file
$json = file_get_contents($json_url);
// decode json datas
$datas = json_decode($json, TRUE);
// get the multi json array
$arrayFeatures = $datas["features"];
// define a new empty array
$arrayTown = array();
// populate the new array with values we need
foreach ($arrayFeatures as $feature) {
array_push($arrayTown, $feature["properties"]["commune"]);
}
// get unique entry for array
$result = array_unique($arrayTown);
// get only vales of array after do array_unique (no index)
$whatIReallyNeed = array_values($result);
// set charset
$charset = "UTF-8";
//set content type
$type = "application/json";
// the best return ever ;)
return response()->json($whatIReallyNeed)->header('Content-type', $type, 'charset', $charset);
} else {
// don't dream
echo "what do you think dude !!!";
}
}
示例3: shouldPassThrough
/**
* Determine if the request has a URI that should pass through CSRF verification.
*
* @param \Illuminate\Http\Request $request
* @return bool
*/
protected function shouldPassThrough($request)
{
if ($request->segment(1) == trim(config('trungtnm.backend.uri'), '/') && $request->isXmlHttpRequest() && Sentinel::check()) {
return true;
}
return false;
}
示例4: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if (!$request->isXmlHttpRequest()) {
$this->errors['reason'] = 'Not XMLHttpRequest';
return json_encode($this->errors);
}
return $next($request);
}
示例5: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next, $role = false)
{
$isAjaxRequest = $request->isXmlHttpRequest() || $request->ajax() || $request->wantsJson();
if (!$isAjaxRequest) {
return redirect('/');
}
return $next($request);
}
示例6: delete
public function delete(Request $request, Category $category)
{
$category->delete();
if ($request->isXmlHttpRequest()) {
return response(json_encode(['success' => true]))->header('Content-type', 'application/json');
} else {
return redirect('/category');
}
}
示例7: 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 $exception)
{
if ($request->isXmlHttpRequest() || $request->ajax() || $request->is('remote/*')) {
$response = response()->json(['error' => $exception instanceof DisplayException ? $exception->getMessage() : 'An unhandled error occured while attempting to process this request.'], 500);
// parent::render() will log it, we are bypassing it in this case.
Log::error($exception);
}
return isset($response) ? $response : parent::render($request, $exception);
}
示例8: shouldCache
/**
* Determine if the given request should be cached;.
*
* @param \Illuminate\Http\Request $request
*
* @return bool
*/
public function shouldCache(Request $request)
{
if ($request->isXmlHttpRequest()) {
return false;
}
if ($this->isRunningInConsole()) {
return false;
}
return $request->isMethod('get');
}
示例9: 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)
{
if ($this->isHttpException($e)) {
if ($request->isXmlHttpRequest()) {
return response()->json(['ret' => 404, 'msg' => 'not fund']);
}
return $this->renderHttpException($e);
} else {
return parent::render($request, $e);
}
}
示例10: 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)
{
if ($e instanceof ModelNotFoundException) {
$e = new NotFoundHttpException($e->getMessage(), $e);
}
// add handler for Ajax requests
if ($request->isXmlHttpRequest()) {
return Response::json(['status' => '500', 'message' => $e->getMessage()], 500);
}
return parent::render($request, $e);
}
示例11: boot
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot(Request $request)
{
if ($this->app->runningInConsole()) {
return false;
}
if ($request->isXmlHttpRequest() || $request->ajax() || $request->wantsJson()) {
return false;
}
$content_pages = Contentpage::pinned()->get();
view()->share('content_pages', $content_pages);
}
示例12: 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)
{
if ($e instanceof ModelNotFoundException) {
$e = new NotFoundHttpException($e->getMessage(), $e);
}
if (config('app.debug')) {
if ($request->isJson() || $request->isXmlHttpRequest()) {
return response(['error' => ['exception' => class_basename($e) . ' in ' . basename($e->getFile()) . ' line ' . $e->getLine() . ': ' . $e->getMessage()]], 500);
}
return $this->renderExceptionWithWhoops($e);
}
return parent::render($request, $e);
}
示例13: store
/**
* @param Storage $storage
* @param Request $request
* @return \Illuminate\Http\RedirectResponse|string
*/
public function store(Storage $storage, Request $request)
{
if ($request->isXmlHttpRequest()) {
$image = $request->file('image');
$timestamp = $this->getFormattedTimestamp();
$savedImageName = $this->getSavedImageName($timestamp, $image);
$imageUploaded = $this->uploadImage($image, $savedImageName, $storage);
if ($imageUploaded) {
$data = ['original_path' => asset('/images/' . $savedImageName)];
return json_encode($data, JSON_UNESCAPED_SLASHES);
}
return "uploading failed";
}
}
示例14: show
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show(Request $request)
{
//Recupera los datos de referencia para crear la tabla de préstamos
if ($request->isXmlHttpRequest()) {
$monto = $request->get('monto');
$quincenas = $request->get('quincenas');
$interes_anual = DB::table('references')->where('months', $quincenas)->value('value') / 100;
$mi_prestamo = new FinantialClass($interes_anual, $quincenas, $monto, 0.16);
$mi_tabla = FinantialClass::create_amorti($mi_prestamo);
return json_encode($mi_tabla);
} else {
return "Datos invalidos";
}
}
示例15: 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)
{
if ($request->isXmlHttpRequest()) {
// moze lepiej bedzie uzyc wantsJson()?
$response = ['error' => 'Przepraszamy, ale coś poszło nie tak. Prosimy o kontakt z administratorem.'];
if (config('app.debug')) {
$response['exception'] = get_class($e);
$response['message'] = $e->getMessage();
$response['trace'] = $e->getTrace();
}
$status = 500;
if ($this->isHttpException($e)) {
$status = $e->getStatusCode();
}
return response()->json($response, $status);
}
return parent::render($request, $e);
}