Skip to content

Commit

Permalink
Adicionado função para retorna estados e cidades.
Browse files Browse the repository at this point in the history
  • Loading branch information
DOUGLASMD1 committed Dec 7, 2018
1 parent b303094 commit 06853df
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 6 deletions.
86 changes: 86 additions & 0 deletions app/Http/Controllers/CidadeController.php
@@ -0,0 +1,86 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Cidade;

class CidadeController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
//
}

/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
}

/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//
}

/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($idestado)
{
$cidades = Cidade::cidades($idestado);
return $cidades;
}

/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
//
}

/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
}

/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
}
18 changes: 12 additions & 6 deletions app/Models/Cidade.php
Expand Up @@ -7,10 +7,16 @@
class Cidade extends Model
{
protected $table = "cidade";

static function cordenadas($id)
{
$cidades=self::all()->where('id','=',$id);
return array_first($cidades);
}

static function cordenadas($id)
{
$cidades=self::all()->where('id','=',$id);
return array_first($cidades);
}

public static function cidades($idestado)
{
$cidades=self::all()->where('estado_id','=',$idestado);
return $cidades;
}
}
16 changes: 16 additions & 0 deletions app/Models/Estado.php
@@ -0,0 +1,16 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Estado extends Model
{
protected $table = "estado";

static function estados()
{
$estados=self::all();
return $estados;
}
}
5 changes: 5 additions & 0 deletions app/Providers/AppServiceProvider.php
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Support\Facades\Schema;
use Illuminate\Support\ServiceProvider;
use App\Models\Estado;

class AppServiceProvider extends ServiceProvider
{
Expand All @@ -15,6 +16,10 @@ class AppServiceProvider extends ServiceProvider
public function boot()
{
Schema::defaultStringLength(191);

view()->composer('auth.register', function ($view) {
$view->with('estados', Estado::estados());
});
}

/**
Expand Down
1 change: 1 addition & 0 deletions routes/web.php
@@ -1,6 +1,7 @@
<?php

Route::redirect('/', '/login');
Route::get('/cidades/{id}', 'CidadeController@show');

Auth::routes();

Expand Down

0 comments on commit 06853df

Please sign in to comment.