dodanie list rozwijanych w tworzeniu jednostki

This commit is contained in:
Krzysztof Strzelecki 2019-09-25 17:46:19 +02:00
parent c633230352
commit e6811a0e90
4 changed files with 239 additions and 13 deletions

View File

@ -27,7 +27,7 @@ class fireStationController extends Controller
'address' => 'required|min:3|max:45', 'address' => 'required|min:3|max:45',
'KRS' => 'required|digits:10', 'KRS' => 'required|digits:10',
'NIP' => 'required|digits:10', 'NIP' => 'required|digits:10',
'phoneNumber' => 'required|digits:11', 'phoneNumber' => 'required|numeric|min:9|max:11',
'email' => 'required|email|unique:firestations', 'email' => 'required|email|unique:firestations',

View File

@ -0,0 +1,145 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class JednostkiTerytorialne extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('wojewodztwa', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
});
Schema::create('powiaty', function (Blueprint $table) {
$table->increments('id');
$table->integer('wojewodztwo_id');
$table->string('name');
});
Schema::create('gminy', function (Blueprint $table) {
$table->increments('id');
$table->integer('wojewodztwo_id');
$table->integer('powiat_id');
$table->string('name');
});
// dane testowe
DB::table('wojewodztwa')->insert(
array(
'name' => 'wielkopolskie'
)
);
DB::table('wojewodztwa')->insert(
array(
'name' => 'pomorskie'
)
);
DB::table('powiaty')->insert(
array(
'wojewodztwo_id' => '1',
'name' => 'poznański'
)
);
DB::table('powiaty')->insert(
array(
'wojewodztwo_id' => '1',
'name' => 'koniński'
)
);
DB::table('powiaty')->insert(
array(
'wojewodztwo_id' => '2',
'name' => 'kartuski'
)
);
DB::table('powiaty')->insert(
array(
'wojewodztwo_id' => '2',
'name' => 'kwidzyński'
)
);
DB::table('gminy')->insert(
array(
'wojewodztwo_id' => '1',
'powiat_id' => '1',
'name' => 'Dopiewo'
)
);
DB::table('gminy')->insert(
array(
'wojewodztwo_id' => '1',
'powiat_id' => '1',
'name' => 'Suchy Las'
)
);
DB::table('gminy')->insert(
array(
'wojewodztwo_id' => '1',
'powiat_id' => '2',
'name' => 'Skulsk'
)
);
DB::table('gminy')->insert(
array(
'wojewodztwo_id' => '1',
'powiat_id' => '2',
'name' => 'Wilczyn'
)
);
DB::table('gminy')->insert(
array(
'wojewodztwo_id' => '2',
'powiat_id' => '3',
'name' => 'Sierakowice'
)
);
DB::table('gminy')->insert(
array(
'wojewodztwo_id' => '2',
'powiat_id' => '3',
'name' => 'Chmielno'
)
);
DB::table('gminy')->insert(
array(
'wojewodztwo_id' => '2',
'powiat_id' => '4',
'name' => 'Gardeja'
)
);
DB::table('gminy')->insert(
array(
'wojewodztwo_id' => '2',
'powiat_id' => '4',
'name' => 'Sadlinki'
)
);
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('wojewodztwa');
Schema::dropIfExists('powiaty');
Schema::dropIfExists('gminy');
}
}

View File

@ -2,6 +2,15 @@
@section('center-area') @section('center-area')
@parent @parent
<head>
<title>Laravel Dependent Dropdown Tutorial With Example</title>
<link rel="stylesheet" href="{{asset('css/app.css')}}">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script>
</head>
<h2>Dodaj Jednostkę</h2> <h2>Dodaj Jednostkę</h2>
<form method="POST" action="/jednostka"> <form method="POST" action="/jednostka">
{{ csrf_field() }} {{ csrf_field() }}
@ -15,21 +24,26 @@
<input type="text" class="form-control" id="number" name="number" value="{{ old('number') }}"> <input type="text" class="form-control" id="number" name="number" value="{{ old('number') }}">
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="voivodeship">Województwo:</label>
<label for="name">Województwo:</label> <select name="voivodeship" class="form-control" style="width:250px">
<input type="text" class="form-control" id="voivodeship" name="voivodeship" value="{{ old('voivodeship') }}"> <option value="">--- Wybierz województwo ---</option>
@foreach ($voivodeships as $key => $value)
<option value="{{ $key }}">{{ $value }}</option>
@endforeach
</select>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="name">Powiat:</label> <label for="county">Powiat:</label>
<input type="text" class="form-control" id="county" name="county" value="{{ old('county') }}"> <select name="county" class="form-control"style="width:250px">
<option>--Wybierz powiat--</option>
</select>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="name">Gmina:</label> <label for="community">Gmina:</label>
<input type="text" class="form-control" id="community" name="community" value="{{ old('community') }}"> <select name="community" class="form-control"style="width:250px">
<option>--Wybierz gminę--</option>
</select>
</div> </div>
<div class="form-group"> <div class="form-group">
@ -48,7 +62,7 @@
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="name">Szerokośc Geograficzna:</label> <label for="name">Szerokość Geograficzna:</label>
<input type="text" class="form-control" id="latitude" name="latitude" value="{{ old('latitude') }}"> <input type="text" class="form-control" id="latitude" name="latitude" value="{{ old('latitude') }}">
</div> </div>
@ -78,10 +92,73 @@
</div> </div>
<div class="form-group"> <div class="form-group">
<button style="cursor:pointer" type="submit" class="btn btn-primary">Submit</button> <button style="cursor:pointer" type="submit" class="btn btn-primary">Submit</button>
</div> </div>
@include('inc.formerrors') @include('inc.formerrors')
</form> </form>
<script type="text/javascript">
jQuery(document).ready(function ()
{
jQuery('select[name="voivodeship"]').on('change',function(){
var voivodeshipID = jQuery(this).val();
if(voivodeshipID)
{
jQuery.ajax({
url : 'jednostka/getcounties/' +voivodeshipID,
type : "GET",
dataType : "json",
success:function(data)
{
//console.log(data);
jQuery('select[name="county"]').empty();
jQuery('select[name="county"]').append(new Option('--Wybierz powiat--', ''));
jQuery('select[name="community"]').empty();
jQuery.each(data, function(key,value){
$('select[name="county"]').append('<option value="'+ key +'">'+ value +'</option>');
});
}
});
}
else
{
$('select[name="county"]').empty();
$('select[name="community"]').empty();
}
});
jQuery('select[name="county"]').on('change',function(){
var countyID = jQuery(this).val();
if(countyID)
{
jQuery.ajax({
url : 'jednostka/getcommunities/' +countyID,
type : "GET",
dataType : "json",
success:function(data)
{
//console.log(data);
jQuery('select[name="community"]').empty();
jQuery.each(data, function(key,value){
$('select[name="community"]').append('<option value="'+ key +'">'+ value +'</option>');
});
}
});
}
else
{
$('select[name="community"]').empty();
}
});
});
</script>
@stop @stop

View File

@ -49,6 +49,10 @@ Route::get('/logout', 'SessionsController@destroy');
Route::get('/jednostka', 'fireStationController@create'); Route::get('/jednostka', 'fireStationController@create');
Route::post('/jednostka', 'fireStationController@store'); Route::post('/jednostka', 'fireStationController@store');
Route::get('/jednostka','DataController@getVoivodeships');
Route::get('/jednostka/getcounties/{id}','DataController@getCounties');
Route::get('/jednostka/getcommunities/{id}','DataController@getCommunities');
//Auth::routes(); //Auth::routes();
// //
//Route::get('/home', 'HomeController@index')->name('home'); //Route::get('/home', 'HomeController@index')->name('home');