php - What are the best practices for creatiang a "settings" model in Laravel 5? -


this first project using laravel (i'm starting 5.2). i'm building self managed website. there's admin should save site settings using later in website. eg: background color, social networks, carousel pictures, products, etc.

my first try creating model "setting" with: id | key (unique) | value. when tried save social networks (to display in site header), realized i'd have save in "value" json url, title, etc... ugly implementation relational model, came conclussion bad. created sepparated model socialnetwork with: id | url | image | name.

now i'm thinking in loading these models @ once in basecontroller can have through controllers, i'm not sure it's correct. mean, array $settings models part of it:

abstract class basecontroller extends controller {     protected $settings;     ...      public function __construct(...)     {         $this->settings = [             'backgroundcolor' => 'red',             'socialnetworks' => socialnetwork::all(),             'other' => other::all(),             ...         ]     } } 

it looks horripilant me, i'm lost framework , don't know what's best deal this. told me service providers, i'm trying figure out advantages of , best approach able made use of these models (to save data) , don't it.

i'm not asking explicit code (it nice however), i'll investigate after understanding approach, tips or conceptual appreciated.

thank you!

this great question. did 1 of code canyon product (krisma cms script) , approach below.

1) created service provider

public function boot()     {         $this->header();         $this->intro();         $this->about();         $this->resume();         $this->portfolio();         $this->services();         $this->stats();         $this->contact();         $this->footer();         $this->section();         $this->codesetting();         $this->customizer();     } 

each of function called in boot declared in provider class below boot function. e.g header section fetched data db via header model , shared globally can accessed in app.

$section = section ::find(1); view()->share('section ', $section); 

2) created table each section i.e about, intro etc , inserted values want modify.

3) in admin panel create form changes/modifications , update desired section properties.

4) fetch data in view. suppose if user has changed background color admin panel red, print out variable right in view style : {{ $sectionname->color }}

5) that's hope gives better idea of how settings can implemented , did product, may there better way found in research , works perfect me.


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -