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');
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
$settings = new Settings();
|
||||
|
||||
foreach ($settings->getForView() as $key => $value) {
|
||||
view()->share($key, $value);
|
||||
}
|
||||
// $settings = new Settings();
|
||||
//
|
||||
// foreach ($settings->getForView() as $key => $value) {
|
||||
// view()->share($key, $value);
|
||||
// }
|
||||
|
||||
$this->extendBlade();
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<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="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="stylesheet" href="{{asset('resources/assets/css/font-awesome.min.css')}}" />
|
||||
|
||||
@@ -60,7 +60,7 @@
|
||||
<div class="sidebar-container">
|
||||
<div class="sidebar-header">
|
||||
<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>
|
||||
<nav class="menu">
|
||||
|
||||
Reference in New Issue
Block a user