How do I modify the configuration file under Laravel Config?

Source: Internet
Author: User
The idea now is to read it as a file and then modify it, but I don't know how to go about it.

In addition, what is the more elegant way? Or are there any ready-made packages available?

ADD:
I mean, like I have a module in the background of the system is the system setup, how can I write a configuration option from request or elsewhere to a specified file, such as config/app.php. Is there any better way or ready-made package recommendations?

Reply content:

The idea now is to read it as a file and then modify it, but I don't know how to go about it.

In addition, what is the more elegant way? Or are there any ready-made packages available?

ADD:
I mean, like I have a module in the background of the system is the system setup, how can I write a configuration option from request or elsewhere to a specified file, such as config/app.php. Is there any better way or ready-made package recommendations?

To have no contact with similar to such a library, but can provide a train of thought, I think the landlord means to join a strategy, and the background can be configured, when the request comes over, priority to check or load this configuration, I don't know if your controller has such a class design, if you use more than Laravel5, all your controllers are inherited from the controller

class UserController extends Controller{}

My advice is to add a base class in the middle, say Basecontroller, and your controller inherits from Basecontroller.

class BaseController extends Controller{}class UserController extends BaseController{}

At this point, you can add the configuration policy that you want to check or load in Basecontroller (either construct () or any other custom function).

Hope to solve your problem.

This configuration, which requires frequent modifications, can be placed in a database or cache, such as Memcache and Redis.

However, the idea is to provide a file that writes to Laravel config:
Laravel The following configuration file basically is an array of return, you can use this method to get the PHP syntax of the array string:

ob_start();var_export(['abc' => 'efc']);$arrStr = ob_get_contents();ob_end_clean();$config = '
  
   

不过这样始终不太安全,建议真要写入文件的话还是用json做配置吧

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.