In my project every user has his/her database and I have defined the connection on config/database.php. So, in the model need to set the database connection.
// defines default database connection
protected $connection = Auth::user()->database;
I can't use this because it will throw an error: Constant expression contains invalid operations
Can anyone help me with this please?
To store and show data, I use:
DB::connection(Auth::user()->database)->table(...
And works like a charm. Can someone help me with $connection to be ble to set it by a variable?
Regards
$this->connection = Auth::user()->database
in your constructor? – Jeremy Harris