本文整理汇总了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();
}
}
}
}
示例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]);
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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]);
}
}
示例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);
}
示例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!']);
}
}
示例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;
}
示例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']);
}
示例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!']);
}
}
示例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');
}
}