mirror of
https://github.com/alextselegidis/easyappointments.git
synced 2024-12-29 01:52:24 +03:00
Added new "page_vars" function that will handle the rendered page variables.
This commit is contained in:
parent
bfef58672c
commit
bfe6664d58
1 changed files with 49 additions and 0 deletions
|
@ -104,3 +104,52 @@ if ( ! function_exists('js_config'))
|
|||
return $value ?? $default;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists('page_vars'))
|
||||
{
|
||||
/**
|
||||
* Get / set the specified JS config value.
|
||||
*
|
||||
* If an array is passed as the key, we will assume you want to set an array of values.
|
||||
*
|
||||
* Example "Get":
|
||||
*
|
||||
* $version = page_vars('title', 'Default Title');
|
||||
*
|
||||
* Example "Set":
|
||||
*
|
||||
* page_vars(['title' => 'Test Title']);
|
||||
*
|
||||
* @param array|string $key Configuration key.
|
||||
* @param mixed $default Default value in case the requested config has no value.
|
||||
*
|
||||
* @return mixed|NULL Returns the requested value or NULL if you assign a new configuration value.
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
function page_vars($key = NULL, $default = NULL)
|
||||
{
|
||||
$page_vars = config('page_vars', []);
|
||||
|
||||
if (empty($key))
|
||||
{
|
||||
return $page_vars;
|
||||
}
|
||||
|
||||
if (is_array($key))
|
||||
{
|
||||
foreach ($key as $item => $value)
|
||||
{
|
||||
$page_vars[$item] = $value;
|
||||
}
|
||||
|
||||
config(['page_vars' => $page_vars]);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$value = $page_vars[$key];
|
||||
|
||||
return $value ?? $default;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue