I don't think (although I might be wrong) that you can just set the $table value to include a different schema? e.g. $table = 'schema_alt.foos'.
What I have done in the past is alter my config to include a new connection - same database, different schema.
'pgsql' => [
'driver' => 'pgsql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '5432'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
'schema' => 'schema_main', // <----- Primary schema
'sslmode' => 'prefer',
],
// Same database, different default schema
'pgsql_alt' => [
'driver' => 'pgsql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '5432'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
'schema' => 'schema_alt', // <----- Alternative Schema
'sslmode' => 'prefer',
],
Then for models that need to reference the alternative schema:
class Foo extends Model
{
$connection = 'pgsql_alt';
// table will now become "schema_alt.foos" as it uses the second connection.
}
Of course, if you have a lot of schemas this might become a bit of a hassle to manage! The query builder will always allow you to join across schemas with far less hassle.