webafra/larasettings

将自定义设置存储在数据库和缓存系统中

dev-master 2019-01-07 14:03 UTC

This package is not auto-updated.

Last update: 2024-09-24 19:27:06 UTC


README

#Laravel 设置

通过 composer 安装

composer require webafra/larasettings

将服务提供者添加到 config/app.php 的 providers 数组中

'providers' => [
    ....
    Webafra\LaraSetting\LaraSettingServiceProvider::class,
]

并将别名添加到 aliases 数组中

'aliases' => [
    ...
    'Setting' => Webafra\LaraSetting\Facade\Setting::class,
]

用法

<?php
namespace App\Http\Controllers;

use Webafra\LaraSetting\Facade\Setting;

class SettingController extends Controller {
    public function index(){
        #Set a Setting property:
        Setting::set('key', 'value');
        
        #Set a Setting property and Set is_primary:
        Setting::set('key', 'value', true);
        
        #Get a Stored Setting value or pass default value
        $setting['key'] = Setting::get('key', 'default value');
    }
    
    public function store(\Request $request){
        #get all settings from an key-value array and store them to database
        #example: <input type="text" name="setting['title']">
        Setting::store($request->input('setting'));
        
        
        #get all settings from an key-value and is primary data array and store them to database
        #example: <input type="text" name="setting['title']">
        Setting::storePrimary($request->input('setting'));


        # and you want Clear All Cache Data With Artisan command Line :
        Setting::clean();
    }
}