G
G
gudron2015-02-22 11:27:01
Laravel
gudron, 2015-02-22 11:27:01

Laravel. Different DB users for web application and migration, is it possible?

How in Laravel5 you can make different database users for a Web application and for migrations.
I would like to get by with the same .env file.
Well, this case is also of interest:
different database users on that part of the WEB application that is available to all visitors and on the part that is administrative.
Well, for example, it is clear that the visitor cannot delete products or other users, which means that the user's database privileges on these tables can be turned off.
I would not really like to arrange a pandemonium with configs for the database at the route level.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
gudron, 2015-02-24
@gudron

As a result, everything was resolved quite simply, in bootstrap/app.php I added:

if($app->runningInConsole()) {

    $app->loadEnvironmentFrom('console.env');

} else {

    if(Illuminate\Http\Request::capture()->segment(1) == 'admin_url' ){
        $app->loadEnvironmentFrom('web_admin.env');
    } else {
        $app->loadEnvironmentFrom('web_client.env');
    }
}

N
naneri, 2015-02-22
@naneri

in env file after:

DB_HOST=localhost
DB_DATABASE=db
DB_USERNAME=name
DB_PASSWORD=pass

put:
then in app/config/database
you create a mysql2 entry and everything is the same as in a regular mysql entry, but instead of
put
Then, in any model that is not in the default database, write
If you rummage around in English, it’s coolly explained here .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question