From c63323035259e4313de7c57f021a257c379e317b Mon Sep 17 00:00:00 2001 From: Krzysztof Strzelecki Date: Wed, 25 Sep 2019 15:46:57 +0200 Subject: [PATCH 1/2] wstepna walidacja tworzenia jednostki --- app/Http/Controllers/fireStationController.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/Http/Controllers/fireStationController.php b/app/Http/Controllers/fireStationController.php index 4611e9d..3a34d01 100644 --- a/app/Http/Controllers/fireStationController.php +++ b/app/Http/Controllers/fireStationController.php @@ -20,6 +20,16 @@ class fireStationController extends Controller public function store() { $this->validate(request(),[ + 'name' => 'required|min:3|max:45', + 'number' => 'required|numeric', + 'postOffice' => 'required|min:3|max:45', + 'zipCode' => 'required|digits:5', + 'address' => 'required|min:3|max:45', + 'KRS' => 'required|digits:10', + 'NIP' => 'required|digits:10', + 'phoneNumber' => 'required|digits:11', + 'email' => 'required|email|unique:firestations', + ]); From e6811a0e9096d8b44611f61274f9f3ad4d2e9f2c Mon Sep 17 00:00:00 2001 From: Krzysztof Strzelecki Date: Wed, 25 Sep 2019 17:46:19 +0200 Subject: [PATCH 2/2] dodanie list rozwijanych w tworzeniu jednostki --- .../Controllers/fireStationController.php | 2 +- ...19_09_19_113737_jednostki_terytorialne.php | 145 ++++++++++++++++++ resources/views/inc/addFireStation.blade.php | 101 ++++++++++-- routes/web.php | 4 + 4 files changed, 239 insertions(+), 13 deletions(-) create mode 100644 database/migrations/2019_09_19_113737_jednostki_terytorialne.php diff --git a/app/Http/Controllers/fireStationController.php b/app/Http/Controllers/fireStationController.php index 3a34d01..1338a78 100644 --- a/app/Http/Controllers/fireStationController.php +++ b/app/Http/Controllers/fireStationController.php @@ -27,7 +27,7 @@ class fireStationController extends Controller 'address' => 'required|min:3|max:45', 'KRS' => 'required|digits:10', 'NIP' => 'required|digits:10', - 'phoneNumber' => 'required|digits:11', + 'phoneNumber' => 'required|numeric|min:9|max:11', 'email' => 'required|email|unique:firestations', diff --git a/database/migrations/2019_09_19_113737_jednostki_terytorialne.php b/database/migrations/2019_09_19_113737_jednostki_terytorialne.php new file mode 100644 index 0000000..59f0176 --- /dev/null +++ b/database/migrations/2019_09_19_113737_jednostki_terytorialne.php @@ -0,0 +1,145 @@ +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'); + } +} diff --git a/resources/views/inc/addFireStation.blade.php b/resources/views/inc/addFireStation.blade.php index b91e622..de6ace7 100644 --- a/resources/views/inc/addFireStation.blade.php +++ b/resources/views/inc/addFireStation.blade.php @@ -2,6 +2,15 @@ @section('center-area') @parent + + + Laravel Dependent Dropdown Tutorial With Example + + + + + +

Dodaj Jednostkę

{{ csrf_field() }} @@ -14,22 +23,27 @@ - - +
- - - + +
-
- - + +
-
- - + +
@@ -48,7 +62,7 @@
- +
@@ -77,6 +91,7 @@ +
@@ -84,4 +99,66 @@ @include('inc.formerrors') + @stop diff --git a/routes/web.php b/routes/web.php index 3091adf..7e6bcd0 100644 --- a/routes/web.php +++ b/routes/web.php @@ -49,6 +49,10 @@ Route::get('/logout', 'SessionsController@destroy'); Route::get('/jednostka', 'fireStationController@create'); 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(); // //Route::get('/home', 'HomeController@index')->name('home');