Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
agendamento
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Marcos Albano
agendamento
Commits
1289b5eb
Commit
1289b5eb
authored
Aug 17, 2020
by
Marcos Albano
💬
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adicionado os metodos OneToMany e ManyToOne ao controller OneToManyController
parent
fcc7b261
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
38 additions
and
49 deletions
+38
-49
OneToManyController.php
app/Http/Controllers/OneToManyController.php
+29
-43
Lote.php
app/Models/Lote.php
+2
-2
Municipio.php
app/Models/Municipio.php
+6
-4
web.php
routes/web.php
+1
-0
No files found.
app/Http/Controllers/OneToManyController.php
View file @
1289b5eb
...
...
@@ -2,56 +2,42 @@
namespace
App\Http\Controllers
;
use
App\Models\Gleba
;
use
App\Models\Lote
;
use
App\Models\Municipio
;
use
App\Models\Titulo
;
use
Illuminate\Http\Request
;
use
Illuminate\Support\Facades\DB
;
class
OneToManyController
extends
Controller
{
public
function
oneToMany
()
{
// //$municipio = Municipio::where('uf', 'CE')->get()->first();
// $municipios = Municipio::whereIn('nome', ['ABAIARA', 'ACARAÚ'])->with('lotes')->get();
// //dd($municipios);
// foreach ($municipios as $municipio) {
// echo "<br><b>{$municipio->nome}</b>";
// $lotes = $municipio->lotes()->get();
// $lotes = $municipio->lotes;
// foreach ($lotes as $lote) {
// echo "<br>{$lote->numero}";
// echo " - {$lote->proprietario}";
// echo " - {$lote->cpf}";
// }
// echo "<hr>";
// }
// $municipios = Municipio::get();
// foreach($municipios as $municipio) {
// $lotes = Lote::where('municipio_id', '=',"{$municipio->id}")->with('titulos')->get();
// //dd($municipio);
// foreach ($lotes as $lote) {
// $lotes = Lote::where(str_replace(array('.', '-'), '', "{$lote->cpf}"))->with('titulos')->get();
// dd($lote);
// echo "<br>Proprietário: {$lote->proprietario}";
// echo "<br>CPF: - {$lote->cpf}";
// echo "<hr>";
// $titulos = $lote->titulos()->get();
// $titulos = $lote->titulos;
// foreach ($titulos as $titulo) {
// echo "<br>Número Título: {$titulo->numero_titulo}";
// }
// }
// }
// RELACIONAMENTO MUNICIPIO/LOTE
//$municipios = Municipio::where('id', 2304277)->get()->first();
//$municipios = Municipio::where('uf', "CE")->orderBy('nome', 'asc')->with('lotes')->get();
$municipios
=
Municipio
::
where
(
'nome'
,
"ERERÊ"
)
->
orderBy
(
'nome'
,
'asc'
)
->
with
(
'lotes'
)
->
get
();
//dd($municipios);
foreach
(
$municipios
as
$municipio
)
{
//echo "<hr>{$municipio->nome}";
// $lotes = $municipio->lotes()
// ->where('cpf', '<>', null)->get();
$lotes
=
$municipio
->
lotes
;
//dd($lotes);
foreach
(
$lotes
as
$lote
)
{
//dd($lote);
//echo "<hr>{$lote->numero}";
}
}
}
public
function
manyToOne
()
{
$loteNumero
=
'0002'
;
$lote
=
Lote
::
where
(
'numero'
,
$loteNumero
)
->
get
()
->
first
();
$municipio
=
$lote
->
municipio
;
//dd($municipio);
//echo "<hr>{$municipio->nome}";
}
}
app/Models/Lote.php
View file @
1289b5eb
...
...
@@ -24,9 +24,9 @@ class Lote extends Model
return
$results
;
}
public
function
titulos
()
public
function
municipio
()
{
return
$this
->
hasOne
(
Lote
::
class
,
277720
);
return
$this
->
belongsTo
(
Municipio
::
class
);
}
}
app/Models/Municipio.php
View file @
1289b5eb
...
...
@@ -20,14 +20,16 @@ class Municipio extends Model
return
$results
;
}
public
function
gleba
()
{
return
$this
->
hasOne
(
Glebas
::
class
);
}
//
public function gleba()
//
{
//
return $this->hasOne(Glebas::class);
//
}
public
function
lotes
()
{
return
$this
->
hasMany
(
Lote
::
class
);
//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');
}
}
routes/web.php
View file @
1289b5eb
...
...
@@ -3,6 +3,7 @@
use
Illuminate\Support\Facades\Auth
;
use
Illuminate\Support\Facades\Route
;
Route
::
get
(
'many-to-one'
,
'OneToManyController@manyToOne'
);
Route
::
get
(
'one-to-many'
,
'OneToManyController@oneToMany'
);
Route
::
get
(
'one-to-one'
,
'OneToOneController@oneToOne'
);
Route
::
any
(
'agendamentos/search'
,
'AgendamentoController@search'
)
->
name
(
'agendamentos.search'
)
->
middleware
(
'auth'
);
//->middleware('auth');
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment