Improved Request Methods

This commit is contained in:
devansh bawari 2021-06-09 14:07:52 +05:30
parent c1abfd7e5f
commit 4fbddaca77
2 changed files with 12 additions and 4 deletions

View File

@ -9,8 +9,8 @@
<div class="content">
@php
$locale = core()->getRequestedLocaleCode();
$channel = core()->getRequestedChannelCode();
$locale = core()->getRequestedLocaleCode('locale', false);
$channel = core()->getRequestedChannelCode(false);
@endphp
<div class="page-header">

View File

@ -235,6 +235,7 @@ class Core
/**
* Get channel code from request.
*
* @param bool $fallback optional
* @return string
*/
public function getRequestedChannelCode($fallback = true)
@ -324,11 +325,18 @@ class Core
* you can pass it as an argument.
*
* @param string $localeKey optional
* @param bool $fallback optional
* @return string
*/
public function getRequestedLocaleCode($localeKey = 'locale'): string
public function getRequestedLocaleCode($localeKey = 'locale', $fallback = true)
{
return request()->get($localeKey) ?: app()->getLocale();
$localeCode = request()->get($localeKey);
if (! $fallback) {
return $localeCode;
}
return $localeCode ?: app()->getLocale();
}
/**