Commit 46cef058 authored by Marcos Albano's avatar Marcos Albano 💬

Mais relacionamento

parent b7364abe
...@@ -2,24 +2,52 @@ ...@@ -2,24 +2,52 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Models\Lote; use App\Models\Etapa;
use App\Models\LoteTramite; use App\Models\Pendencia;
use App\Models\Tramite; use App\Models\SecUser;
use App\Models\Setor;
class OneToManyController extends Controller class OneToManyController extends Controller
{ {
public function oneToMany() public function oneToMany()
{ {
$secUsers = SecUser::where('id', 79)->with('lotes')->get();
dd($secUsers);
// $pendencias = Pendencia::where('etapa_id', 1)->with('processos')->limit(1)->get();
// dd($pendencias);
// $etapas = Etapa::where('setor_id', 2)->with('pendencias')->get();
// dd($etapas);
// $etapas = Etapa::where('setor_id', 99)->with('setores')->get();
// dd($etapas);
/* RELACIONAMENTO LOTE/LOTE_TRAMITE */ /* RELACIONAMENTO LOTE/LOTE_TRAMITE */
$lotesTramites = LoteTramite::where('lote_id', 410251)->with('tramites')->get(); // $tramites = Tramite::where('id', 2)->with('setor')->get();
foreach($lotesTramites as $loteTramite){ // //dd($tramites);
$tramites = $loteTramite->tramites()->get();
foreach($tramites as $tramite){ // foreach($tramites as $tramite){
echo "lote_Tramite: {$loteTramite->tramite_id}<hr>"; // echo "{$tramite->nome}";
echo "Nome Tramite: {$tramite->nome}<hr>";
} // $setores = $tramite->setor()->get();
} // dd($setores);
// }
// $setor = Setor::where('nome', 'NUGEO')->with('tramites')->get();
// dd($setor);
/* RELACIONAMENTO LOTE/LOTE_TRAMITE */
// $lotesTramites = LoteTramite::where('lote_id', 410251)->with('tramites')->get();
// foreach($lotesTramites as $loteTramite){
// $tramites = $loteTramite->tramites()->get();
// foreach($tramites as $tramite){
// echo "lote_Tramite: {$loteTramite->tramite_id}<hr>";
// echo "Nome Tramite: {$tramite->nome}<hr>";
// }
// }
/* RELACIONAMENTO LOTE/LOTE_TRAMITE */ /* RELACIONAMENTO LOTE/LOTE_TRAMITE */
// $lotes = Lote::where('id', 410251)->with('lotesTramites')->get(); // $lotes = Lote::where('id', 410251)->with('lotesTramites')->get();
......
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Etapa extends Model
{
protected $table = 'sige.etapas';
public function setores()
{
return $this->hasMany(Setor::class, 'id', 'setor_id');
}
public function pendencias()
{
return $this->hasMany(Pendencia::class, 'etapa_id', 'id');
}
public function processos()
{
return $this->hasMany(Processo::class, 'etapa_id', 'id');
}
}
...@@ -7,22 +7,15 @@ use Illuminate\Database\Eloquent\Model; ...@@ -7,22 +7,15 @@ use Illuminate\Database\Eloquent\Model;
class Lote extends Model class Lote extends Model
{ {
protected $table = 'sige.lotes'; protected $table = 'sige.lotes';
protected $fillable = ['id', 'area', 'ativo', 'criado_por_id', 'dhc', 'dhm', 'modificado_por_id', // protected $fillable = ['id', 'area', 'ativo', 'criado_por_id', 'dhc', 'dhm', 'modificado_por_id',
'municipio_id', 'nome', 'numero', 'perimetro', 'proprietario', 'situacao_juridica_id', // 'municipio_id', 'nome', 'numero', 'perimetro', 'proprietario', 'situacao_juridica_id',
'titulo', 'sncr', 'cpf', 'protocolo', 'is_aprovado', 'data_termino_periodo_de_uso', // 'titulo', 'sncr', 'cpf', 'protocolo', 'is_aprovado', 'data_termino_periodo_de_uso',
'status_estrutura', 'status_pessoa', 'status_uso', 'comunidade', 'localidade', 'projeto_especial', // 'status_estrutura', 'status_pessoa', 'status_uso', 'comunidade', 'localidade', 'projeto_especial',
'cnpj', 'status_titulo', 'migrado_para_access', 'cod_imo_rur']; // 'cnpj', 'status_titulo', 'migrado_para_access', 'cod_imo_rur'];
public function search($filter = null) // public function secUser(){
{ // return $this->belongsTo(SecUser::class);
$results = $this->where(function ($query) use ($filter) { // }
if ($filter) {
$query->where('proprietario', 'LIKE', "%{$filter}%");
}
}) //->toSql();
->paginate();
return $results;
}
public function municipio() public function municipio()
{ {
...@@ -56,4 +49,15 @@ class Lote extends Model ...@@ -56,4 +49,15 @@ class Lote extends Model
return $this->hasMany(LoteTramite::class, 'lote_id', 'id'); return $this->hasMany(LoteTramite::class, 'lote_id', 'id');
} }
public function search($filter = null)
{
$results = $this->where(function ($query) use ($filter) {
if ($filter) {
$query->where('proprietario', 'LIKE', "%{$filter}%");
}
}) //->toSql();
->paginate();
return $results;
}
} }
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Pendencia extends Model
{
protected $table = 'sige.pendencias';
public function processos()
{
return $this->hasMany(Processo::class, 'pendencia_id', 'id');
}
}
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class SecUser extends Model
{
protected $table = 'public.sec_user';
public function lotes()
{
return $this->hasMany(Lote::class, 'criado_por_id', 'id', 'modificado_por_id');
}
public function secUser()
{
return $this->hasMany(SecUser::class);
}
}
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Setor extends Model
{
protected $table = 'sige.setores';
public function tramites()
{
return $this->hasMany(Tramite::class, 'id');
}
}
...@@ -8,12 +8,12 @@ class SituacaoJuridica extends Model ...@@ -8,12 +8,12 @@ class SituacaoJuridica extends Model
{ {
protected $table = 'sige.situacoes_juridicas'; protected $table = 'sige.situacoes_juridicas';
public function lote() // public function lote()
{ // {
return $this->belongsTo(Lote::class); // return $this->belongsTo(Lote::class);
//CASO FOSSE VINCULAR COM SITUAÇÃO JURÍDICA (ESSE id SERIA O id DA TABELA sige.situacoes_juridicas) - AULA 9 // //CASO FOSSE VINCULAR COM SITUAÇÃO JURÍDICA (ESSE id SERIA O id DA TABELA sige.situacoes_juridicas) - AULA 9
// return $this->hasMany(Lote::class, 'municipio_id', 'id'); // // return $this->hasMany(Lote::class, 'municipio_id', 'id');
} // }
public function lotes() public function lotes()
{ {
......
...@@ -8,4 +8,15 @@ class Tramite extends Model ...@@ -8,4 +8,15 @@ class Tramite extends Model
{ {
protected $table = 'sige.tramites'; protected $table = 'sige.tramites';
public function setor()
{
return $this->belongsTo(Setor::class, 'id');
}
public function setores()
{
return $this->hasMany(Setor::class, 'id');
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment