Link to home
Start Free TrialLog in
Avatar of Ramy Mohsen
Ramy Mohsen

asked on

Laravel 5, I want to change the location of a config file.

Hi,

I want to change the location of the database.php file which is a configuration file, I want to put it in another location in the system.

How can I achieve that?
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

To quote the Laravel docs...
All of the configuration files for the Laravel framework are stored in the config directory.
 The configuration includes the database.  Since Laravel favors convention over configuration, we don't usually change things like this.  Maybe if you can tell us why you want to change the location we can suggest a useful approach.
Avatar of Ramy Mohsen
Ramy Mohsen

ASKER

My case is that I want users to subscribe to some service that I will provide.
When a user subscribe to a service, a new Database will be created to store his data.
So I will provide SAAS, many databases, with the same code.

So for each user there will be a config file congaing the connection credentials for his database,  and I will tell laravel to use one of these config files based on some data saved related his user account in a central DB.


I think laravel must be more flexible than obligating me to use some approach.
Laravel has a way to use different database connections.  It's part of the "basic database usage" for the Eloquent ORM.  You specify the database connection by name.  To quote the Eloquent docs
... you may define a connection property to override the name of the database connection that should be used when utilizing the model.
See if this helps make sense of it:
http://laravel.com/docs/5.0/database#accessing-connections
http://laravel.com/docs/5.0/eloquent#basic-usage
Thank you for your help.

But, I still don't want to implement this due to many reasons:

1- I don't want to open the database.php config file manually to add a new connection for each new database created( which means for each new subscription),
nor automatically doing that using PHP, because I think that opening file, reading its contents then changing them by addition will not be efficient, and this may occur while another request is being done to the site, which may reqiure use of the file is will be edited in that time.

2- If there is a good way to add these connections automatically, then I think that laravel may load the connections array and then
use the connection that I require from inside it, which means memory load in case that I have 1000 connection ( Note, My project is supposed to get more subscriptions than 1000
So my solution is to find some way to create new database.php file for each database, these files will be but in a folder named 'databases/{subscriber_name}'
So I will be able to access only the required connection credentials if I could tell laravel to use the needed path which will contain a variable portion.
SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I don't have any way to test the code, but if it's working fine for you, that's a very good sign!
Thanks, but I'm not asking that you test it, because I tested it and it's working fine.

I'm asking about your opinion of that solution, and if you think it's not good to take this way for any consideration.

Thanks again :)
I don't really have anything else to add.  I think the LaraCasts team will be a good source of ideas.

Best of luck with the project, ~Ray
Because I deeply investigated the problem and  was able to solve it. then I wrote my solution here and hence accepted it.