How to edit and save custom config files in Laravel?

前端 未结 4 641
鱼传尺愫
鱼传尺愫 2021-02-04 16:47

I am creating simple web application in Laravel 4. I have backend for managing applications content. As a part of backend i want to have UI to manage applications settings. I wa

4条回答
  •  情书的邮戳
    2021-02-04 17:19

    You'll have to extend the Fileloader, but it's very simple:

    class FileLoader extends \Illuminate\Config\FileLoader
    {
        public function save($items, $environment, $group, $namespace = null)
        {
            $path = $this->getPath($namespace);
    
            if (is_null($path))
            {
                return;
            }
    
            $file = (!$environment || ($environment == 'production'))
                ? "{$path}/{$group}.php"
                : "{$path}/{$environment}/{$group}.php";
    
            $this->files->put($file, '

    Usage:

    $l = new FileLoader(
        new Illuminate\Filesystem\Filesystem(), 
        base_path().'/config'
    );
    
    $conf = ['mykey' => 'thevalue'];
    
    $l->save($conf, '', 'customconfig');
    

提交回复
热议问题