I can set 2 different databases in config\database.php with
'conection' => ['database01' => [ ...
'conection' => ['database02' => [ ...
And in the model with
protected $connection = '1database';
protected $connection = '2database';
However, I want to use one controller and insert a conditional something like below
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
if (\Session::get('db')=='database01'){
use App\Model01;
}else{
use App\Model02;
}
Unfortunately, this solution does not work.
public function index()
{
if ($baseDat1){
$data= Data01::orderBy('id', 'desc')->take(25)->get();
}else{
$data= Data02::orderBy('id', 'desc')->take(25)->get();
}
}
Is it possible to do something like I want?