Hi good people. Have been stuck for hours on end with model binding with dynamic DB connection. I have a multi-tier system, more like SAS app, where users can log into different databases depending on the organization. I have managed to do this with the middleware, where it picks the user's ID and is able to refresh connection by pointing to another database. Generally it is done with the following code;
\DB::purge(\DEV::ORG_CONN); \Config::set('database.connections.orgdb.database', \Auth::user()->db); \DB::connection(\DEV::ORG_CONN)->reconnect();
Now when I set up route binding in the RouteServiceProvider, am unable to access the Auth::user() It is returning null. Apparently it is loaded after routes are bound. Is there a way to ensure Routes are bound after Auth has been loaded?
Thanks @xtreem But that is not what am looking for. I need to switch the database from within a given connection on the fly. Setting $connection in the model has been done, now the issue is changing the database in that connection for route model binding.
I hope it is clear.
Sign in to participate in this thread!