FEATURE: make settings accessible only using helper class/function
This commit is contained in:
@@ -0,0 +1,62 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Helpers;
|
||||||
|
|
||||||
|
use App\Models\Settings as SettingsModel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Settings
|
||||||
|
*
|
||||||
|
* Helper class for easier obtaining system settings
|
||||||
|
*
|
||||||
|
* @package App\Helpers
|
||||||
|
*/
|
||||||
|
class Settings
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var array List of all used settings
|
||||||
|
*/
|
||||||
|
protected static $settings;
|
||||||
|
/**
|
||||||
|
* @var bool Are data already initialized?
|
||||||
|
*/
|
||||||
|
protected static $initialized = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for settings determined with key.
|
||||||
|
*
|
||||||
|
* @param string $key settings key
|
||||||
|
* @param string|null $default default value, which will be returned when given key does not exist
|
||||||
|
*
|
||||||
|
* @return string|null
|
||||||
|
*/
|
||||||
|
public static function get($key, $default = null)
|
||||||
|
{
|
||||||
|
self::init();
|
||||||
|
|
||||||
|
return isset(self::$settings->$key) ? self::$settings->$key : $default;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all settings
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function all()
|
||||||
|
{
|
||||||
|
self::init();
|
||||||
|
|
||||||
|
return self::$settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize settings array
|
||||||
|
*/
|
||||||
|
private static function init()
|
||||||
|
{
|
||||||
|
if (!self::$initialized) {
|
||||||
|
$model = new SettingsModel();
|
||||||
|
self::$settings = $model->getAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,3 +12,15 @@ function e($value)
|
|||||||
{
|
{
|
||||||
return htmlspecialchars($value, ENT_QUOTES, 'UTF-8');
|
return htmlspecialchars($value, ENT_QUOTES, 'UTF-8');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shortcut for \App\Helpers\Settings::get()
|
||||||
|
*
|
||||||
|
* @param $key
|
||||||
|
* @param null $default
|
||||||
|
*
|
||||||
|
* @return null|string
|
||||||
|
*/
|
||||||
|
function setting($key, $default = null) {
|
||||||
|
return \App\Helpers\Settings::get($key, $default);
|
||||||
|
}
|
||||||
@@ -21,11 +21,11 @@ class GlobalViewDataProvider extends ServiceProvider
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$settings = new Settings();
|
// $settings = new Settings();
|
||||||
|
//
|
||||||
foreach ($settings->getForView() as $key => $value) {
|
// foreach ($settings->getForView() as $key => $value) {
|
||||||
view()->share($key, $value);
|
// view()->share($key, $value);
|
||||||
}
|
// }
|
||||||
|
|
||||||
$this->extendBlade();
|
$this->extendBlade();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta http-equiv="x-ua-compatible" content="ie=edge">
|
<meta http-equiv="x-ua-compatible" content="ie=edge">
|
||||||
<title>@yield('pageHeading') {{isset($pageName) ? ' | '.$pageName: ''}}</title>
|
<title>@yield('pageHeading') {{setting('pageName')}}</title>
|
||||||
<meta name="description" content="">
|
<meta name="description" content="">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<link rel="stylesheet" href="{{asset('resources/assets/css/font-awesome.min.css')}}" />
|
<link rel="stylesheet" href="{{asset('resources/assets/css/font-awesome.min.css')}}" />
|
||||||
|
|||||||
@@ -60,7 +60,7 @@
|
|||||||
<div class="sidebar-container">
|
<div class="sidebar-container">
|
||||||
<div class="sidebar-header">
|
<div class="sidebar-header">
|
||||||
<div class="m-t-15 text-center text-primary">
|
<div class="m-t-15 text-center text-primary">
|
||||||
<h4>{{isset($pageName) ? str_limit($pageName, 15) : ''}}</h4>
|
<h4>{{str_limit(setting('pageName'), 15)}}</h4>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<nav class="menu">
|
<nav class="menu">
|
||||||
|
|||||||
Reference in New Issue
Block a user