0
Good morning.
I am trying to use 2 mysql tables, as if they were 2 schemas, however I am not getting, I tried the examples:
https://www.bugginhoacademy.com.br/blog/trabalhando-com-mais-de-um-banco-de-dados-no-laravel/
Multiple schemas in Laravel 5 database
But it didn’t work, you can help me?
Filing cabinet .env
DB_CONNECTION=banco1
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=banco1
DB_USERNAME=root
DB_PASSWORD=
DB_CONNECTION2=banco2
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=banco2
DB_USERNAME=root
DB_PASSWORD=
Model
<?php
namespace App\Conexoes;
use Illuminate\Database\Eloquent\Model;
class Conexoes extends Model
{
//
protected $connection = 'gps';
}
Controller
namespace App\Http\Controllers\Rastreamento;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Conexoes\Positions;
use App\Rastreamento\Markers;
use Mapper;
class PosiceosController extends Controller
{
private $positions;
public function index(){
$this->setConnection('banco2');
$registros= $this->tabela->all();
}
Enter the code you are using and the error that is showing
– Isac
.env = DB_CONNECTION=banco1
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=banco1
DB_USERNAME=root
DB_PASSWORD=

DB_CONNECTION2=banco2
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=banco2
DB_USERNAME=root
DB_PASSWORD=

Model:
– Carlos Alexandre R Ramos
What mistake appears to you?
– DNick
It only finds the first connection and does not find the table because it is on the second connection
– Carlos Alexandre R Ramos
you said you followed the example of the first link, but it is missing code in your example. Is your code exactly the same as link 1? Another thing the example version was in Laravel 5.4. It’s the same as yours?
– DNick
Yes and the same 5.4
– Carlos Alexandre R Ramos