I tried to change the database connection from laravel model,
This is my code,
namespace App\model;
use Illuminate\Database\Eloquent\Model;
use Config;
use DB;
class Process extends Model
{
config(['database.connections.newsql' => [
'host' => '127.0.0.1',
'password' => '',
'database' => 'gps_bizspecific',
'username' => 'root'
]]);
But I got an error
syntax error, unexpected 'config' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST)
How to solve this ???
NOTE : I dont want to update config/database.php., I need to pass the database name (stored in a section variable) from model
Situation :
When a user register in my site it will create a dedicated database for each user, so when each user login to my site i need to fetch datas from corresponding user database
I have a central database with all user details and database names, when a user login I fetch the datatabse name from the central database and stored it into a session variable. after that I need to create a connection with that new database
Thank you.
use Config;
because u are using config helper function – Jignesh Joisar