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


PHP Request::cookie方法代码示例

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


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

示例1: store

 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request, ApiService $apiService)
 {
     /*
     Do some basic validation beause the form is a perfect representation of the resource on the api side.
     TODO, might want to move this into the a WWW service layer if it gets out of hand? (can it be tested well here?)
     */
     $validator = Validator::make($request->all(), ['name' => 'required', 'msw_country' => 'required'], ['msw_country.required' => 'Please select the location']);
     if ($validator->fails()) {
         return redirect(route('spot.create'))->withErrors($validator)->withInput();
     }
     /** **/
     $response = $apiService->post(route('api.v1.0.spot.store'), $request->only(['msw_spot_id', 'name', 'public']))->addHeader(['Authorization' => 'Bearer ' . $request->cookie('token')])->dispatch();
     if ($response->getStatusCode() === 200) {
         //update the user's country as a convenience
         $payload = json_decode(base64_decode(explode('.', $request->cookie('token'))[1]));
         //this gets the JWT payload. Can be faked by the user, but the API server side will be validating the request
         $apiService->patch(route('api.v1.0.user.update', $payload->sub), $request->only('msw_country'))->addHeader(['Authorization' => 'Bearer ' . $request->cookie('token')])->dispatch();
         return redirect(route($request->get('from_route') ?: 'dashboard'));
     } else {
         if ($response->getStatusCode() === 400) {
             $content = $response->getContent();
             return redirect(route('spot.create'))->withErrors((array) $content->errors)->withInput();
         } else {
             if ($response->getStatusCode() === 403) {
                 return redirect(route('login'))->withErrors(['generic' => ['Your session has expired, please login again']]);
             } else {
                 return redirect(route('spot.create'))->withErrors(['generic' => ['There was a problem with the system, please try again']])->withInput();
             }
         }
     }
 }
开发者ID:shauno,项目名称:sesh.co.za,代码行数:37,代码来源:SpotController.php

示例2: show

 public function show(Request $request)
 {
     $stylesData = \Theme::GetCSS();
     $styles = null;
     if (file_exists($stylesData['path'])) {
         $styles = $stylesData['path'];
     }
     $styles = explode('/', $styles);
     $styles = array_pop($styles);
     // now check for cookies
     $cookie_list = $request->cookie('list_joined');
     $showList = false;
     $showThankyou = false;
     // check if there is a default list
     if (\Configuration::get('default_list')) {
         $showList = true;
     }
     if (isset($cookie_list) && $cookie_list == \Configuration::get('default_list')) {
         $showList = false;
         if ($request->cookie('list_cid')) {
             // check if the user is on the current list...
             $member = ListMember::find($request->cookie('list_cid'));
             if ($member->list_id == \Configuration::get('default_list')) {
                 $showThankyou = true;
             }
         }
     }
     return \Theme::display('home.front', ['user' => \Auth::user(), 'styles' => $styles, 'showList' => $showList, 'thankyou' => $showThankyou]);
 }
开发者ID:hramose,项目名称:laravel5-admin,代码行数:29,代码来源:HomeController.php

示例3: handle

 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     if (!$request->cookie('shy_first_id') && !$request->cookie('shy_first_sex')) {
         return new RedirectResponse(url('/'));
     }
     return $next($request);
 }
开发者ID:niksrc,项目名称:SF,代码行数:14,代码来源:cookieMiddleware.php

示例4: handle

 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     // Detect the bot case => if bot we do nothing
     $isBot = isset($_SERVER['HTTP_USER_AGENT']) && preg_match('/bot|crawl|slurp|spider/i', $_SERVER['HTTP_USER_AGENT']);
     /**
      * If User has never been logged => it will be redirected to his local url
      */
     if (!$request->cookie('locale') && !$isBot) {
         $locale = \App::getLocale();
         // if local doesn't match the current user local => we redirect
         $preferedLocale = $request->getPreferredLanguage($this->locales);
         // If local doesn't match the current user => we redirect the user to the correct url
         if ($locale !== $preferedLocale) {
             // Get Locales of the preferred local
             Session::put('locale', $preferedLocale);
         }
     } elseif ($request->cookie('locale')) {
         Session::put('locale', $request->cookie('locale'));
     }
     if ($request->has('force_locale')) {
         Session::put('locale', $request->get('force_locale'));
         \App::setLocale(Session::get('locale', env('APP_DEFAULT_LOCALE', 'en')));
         return $next($request)->withCookie(cookie()->forever('locale', Session::get('locale')));
     }
     \App::setLocale(Session::get('locale', env('APP_DEFAULT_LOCALE', 'en')));
     return $next($request);
 }
开发者ID:philippejadin,项目名称:Mobilizator,代码行数:34,代码来源:RedirectLang.php

示例5: handle

 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     if ($request->has('lang') && Languages::has($request->input('lang'))) {
         // 1. Check URL parameter
         $locale = $request->input('lang');
         App::setLocale($locale);
         // Logged-in users: save to database
         if (Auth::check()) {
             $user = Auth::user();
             $user->locale = $locale;
             $user->save();
         }
         Cookie::queue('locale', $locale, 24 * 60);
     } elseif (Auth::check() && Languages::has(Auth::user()->locale)) {
         // 2. Check database for logged in users
         App::setLocale(Auth::user()->locale);
     } elseif (Languages::has($request->cookie('locale'))) {
         // 3. Check cookies
         App::setLocale($request->cookie('locale'));
     } elseif (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
         // 4. Check browser languages. Note that Googlebot do not have this.
         $accept_languages = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
         foreach ($accept_languages as $lang) {
             $lang = locale_accept_from_http($lang);
             $locale = locale_lookup(Languages::all(), $lang, true, 'en');
             if (!empty($locale)) {
                 App::setLocale($locale);
                 break;
             }
         }
     }
     setlocale(LC_TIME, Languages::withRegion(App::getLocale()) . '.utf8');
     return $next($request);
 }
开发者ID:santakani,项目名称:santakani.com,代码行数:41,代码来源:LocaleDetect.php

示例6: forLimit

 /**
  * @param \Illuminate\Http\Request $request
  * @param string $currentPath
  * @return mixed
  */
 public static function forLimit($request, $currentPath)
 {
     if (!$request->has('limit') && $request->cookie($currentPath . '_perPage')) {
         return $request->cookie($currentPath . '_perPage');
     }
     return false;
 }
开发者ID:timurbakarov,项目名称:laravel-table-view,代码行数:12,代码来源:LookInStorage.php

示例7: guess

 /**
  * Detect the user's desired locale.
  *
  * @param  bool $must_return_value
  * @return string|null
  */
 public function guess($must_return_value = false)
 {
     $locale = $this->request->cookie($this->cookieKey);
     if ($locale && $this->isAvailable($locale)) {
         return $locale;
     }
     return $this->pickFromAccepted($this->available, $this->getHeaderAcceptedLocales(), $must_return_value);
 }
开发者ID:hpkns,项目名称:laravel-i18n,代码行数:14,代码来源:LocaleManager.php

示例8: index

 /**
  * Get the homepage content and metadata.
  *
  * @param Request $request
  * @return Response
  */
 public function index(Request $request)
 {
     //Get the projects, eager load the project images and skills
     $projects = Project::with('images', 'skills')->get();
     //Check if the contact submission cookie has been set
     $contacted = $request->cookie('cconf') ? $request->cookie('cconf') : false;
     return view('public.home')->withContacted($contacted)->withProjects($projects);
 }
开发者ID:justincdotme,项目名称:justincdotme,代码行数:14,代码来源:HomeController.php

示例9: ensureUser

 public function ensureUser($forceSession = false)
 {
     if (!Session::has(config('laravel-ab.cache_key')) || $forceSession) {
         $uid = md5(uniqid() . $this->request->getClientIp());
         $laravel_ab_id = $this->request->cookie(config('laravel-ab.cache_key'), $uid);
         Session::set(config('laravel-ab.cache_key'), $uid);
     }
     if (empty(self::$session)) {
         self::$session = Instance::firstOrCreate(['instance' => Session::get(config('laravel-ab.cache_key')), 'identifier' => $this->request->getClientIp(), 'metadata' => function_exists('laravel_ab_meta') ? call_user_func('laravel_ab_meta') : null]);
     }
 }
开发者ID:comocode,项目名称:laravel-ab,代码行数:11,代码来源:Ab.php

示例10: get

 /**
  * {@inheritDoc}
  */
 public function get()
 {
     $key = $this->key;
     // Cannot use $this->jar->queued($key, function()) because it's not
     // available in 4.0.*, only 4.1+
     $queued = $this->jar->getQueuedCookies();
     if (isset($queued[$key])) {
         return $queued[$key];
     }
     return $this->request->cookie($key);
 }
开发者ID:kevin416,项目名称:admin,代码行数:14,代码来源:IlluminateCookie.php

示例11: rentItem

 public function rentItem(Request $request, $id)
 {
     /* Insert new reservation into database */
     if ($request->cookie('user_id') != null && $request->cookie('privilege') != null) {
         $user_id = $request->cookie('user_id');
         DB::insert('INSERT INTO reservations (user_id, product_id) VALUES (:user_id, :id)', ['id' => $id, 'user_id' => $user_id]);
         return redirect()->action('InventoryController@index', ['message' => 'Success!']);
     } else {
         return redirect()->action('StartController@login', ['message' => 'Not logged in!']);
     }
 }
开发者ID:WebTech2015,项目名称:App30,代码行数:11,代码来源:InventoryController.php

示例12: getUserFromCookies

 protected function getUserFromCookies(Request $request)
 {
     $user = null;
     if (!is_null($request->cookie('userId'))) {
         $user = User::find($request->cookie('userId'));
     }
     if (!$user) {
         $user = new User();
     }
     return $user;
 }
开发者ID:hogggy,项目名称:infinite-wonder,代码行数:11,代码来源:Controller.php

示例13: getMobileIndex

 public function getMobileIndex(Request $request)
 {
     if (!$request->session()->has("id")) {
         if (!$request->cookie("id")) {
             return response()->json(['status' => 'notLogin']);
         } else {
             $request->session()->put('id', $request->cookie("id"));
             return response()->json(['status' => 'success']);
         }
     }
     return response()->json(['status' => 'success']);
 }
开发者ID:TrinhThiThuyDung,项目名称:letsgo,代码行数:12,代码来源:MainController.php

示例14: account

 public function account(Request $request)
 {
     /* Get account info */
     if ($request->cookie('user_id') != null) {
         $user_id = $request->cookie('user_id');
         $account = DB::select('SELECT user_id, username, privileges FROM users WHERE user_id = :user_id', ['user_id' => $user_id]);
         $reservations = DB::select('SELECT productname, imgurl, description, reservation_id FROM products, reservations WHERE user_id=:user_id AND reservations.product_id=products.product_id', ['user_id' => $user_id]);
         /* View the rented items */
         return view('inventory.account')->with(['account' => $account[0], 'reservations' => $reservations]);
     } else {
         return redirect()->action('StartController@login', ['message' => 'Not logged in!']);
     }
 }
开发者ID:WebTech2015,项目名称:App30,代码行数:13,代码来源:UserController.php

示例15: register

 public function register(Request $request)
 {
     /* View register page */
     if ($request->cookie('user_id') != null && $request->cookie('privilege') != null) {
         if ($request->cookie('privilege') == "admin") {
             return redirect()->action('AdminController@index');
         } else {
             return redirect()->action('InventoryController@index');
         }
     } else {
         return view('start.register');
     }
 }
开发者ID:WebTech2015,项目名称:App30,代码行数:13,代码来源:StartController.php


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