1
I’m a beginner in Laravel and I’m trying to bring data from a BD with multiple Postgresql schemas with Laravel 5.1 and is bringing me an error
What configuration should be done for the model to correctly access the table of that schema?
Directly by postgres would write the query this way:
SELECT * FROM cadastro.escolaridade
SELECT * FROM schema.tabela
Errorexception in Testecontroller.php line 13: Use of Undefined Registration form - assumed 'registration'
Database.php
'pgsql' => [
'driver' => 'pgsql',
'host' => env('DB_HOST', '127.0.0.1'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
],
Model
<?php
namespace App\Models\Programas;
use Illuminate\Database\Eloquent\Model;
class Cadastro extends Model
{
}
Controller
<?php
namespace App\Http\Controllers;
use App\Models\Programas\Cadastro;
class TesteController extends Controller
{
public function getIndex()
{
$escolaridade = cadastro.escolaridade::all();
return view('programas.escrituras.index', compact('escolaridade'));
}
View
@forelse($escolaridade as $descricao)
<p><b>Grau de Escolaridade:</b>{{$descricao->descricao}}</p>
@empty
<p>Nenhum Grau Cadastrado!</p>
@endforelse
Cadastro::all()
returns something?cadastro.escolaridade::all();
does not refer to class or schema. MaybeCadastro
has a property called$escolaridade
.– rray
Maybe that answer can help.
– rray
I will give my opinion by marking his question. (This error cannot be reproduced, such and such)
– Wallace Maxters
The error is not part of those files, you are getting the message, but the problem comes from elsewhere... you better figure out the problem, use Xdebug or Phpunit to test your classes. Or something simpler, like
die();
var_dump()
andprint_r()
.– Ivan Ferrer
@Ivanferrer the syntax
cadastro.escolaridade::all();
who is in theTesteController
is invalid, it seems to me that he wants to know how to model consult a bank in one or multiple schemas.– rray
By the logic of error, he is not finding the constant, give a look here.
– Ivan Ferrer
Have you checked in the site of the Laravel ?
– Ivan Ferrer
In PHP there is no such syntax with dot in PHP, at least not that I know:
cadastro.escolaridade::all()
what is there is that:{string1.string2}
or this$cadastro->escolaridade::all()
.– Ivan Ferrer
I took the negative that I had given. But I think the question should be reworked.
– Wallace Maxters
Maybe what he wants to do is something like this:;
$escolaridade = Cadastro->escolaridade::all();
– Ivan Ferrer