Dodanie edycji jednostki
This commit is contained in:
parent
7a5443ac10
commit
84e6b5ed62
@ -16,13 +16,26 @@ class fireStationController extends Controller
|
|||||||
} else{
|
} else{
|
||||||
$voivodeships = DB::table('wojewodztwa')->pluck("name","id");
|
$voivodeships = DB::table('wojewodztwa')->pluck("name","id");
|
||||||
return view('unit',compact('voivodeships'));
|
return view('unit',compact('voivodeships'));
|
||||||
//return view('unit');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function editForm()
|
||||||
|
{
|
||||||
|
if(auth()->user() != null && auth()->user()->fireStationID != null )
|
||||||
|
{
|
||||||
|
$id = auth()->user()->fireStationID;
|
||||||
|
$fireStation = DB::table('firestations')->where("id", $id)->first();
|
||||||
|
$voivodeships = DB::table('wojewodztwa')->pluck("name","id");
|
||||||
|
return view('fireStationEdit', ["fireStation" => $fireStation], compact('voivodeships'));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return "Brak dostępu";
|
||||||
|
}
|
||||||
|
|
||||||
public function store()
|
public function store()
|
||||||
{
|
{
|
||||||
$this->validate(request(),[
|
$this->validate(request(),[
|
||||||
'unitName' => 'required|min:3|max:45',
|
'fireStationName' => 'required|min:3|max:45',
|
||||||
'number' => 'required|numeric',
|
'number' => 'required|numeric',
|
||||||
'voivodeship' => 'required',
|
'voivodeship' => 'required',
|
||||||
'county' => 'required',
|
'county' => 'required',
|
||||||
@ -57,7 +70,7 @@ class fireStationController extends Controller
|
|||||||
$community = DB::table('gminy')->select('name')->where('id', $request -> community)->first();
|
$community = DB::table('gminy')->select('name')->where('id', $request -> community)->first();
|
||||||
|
|
||||||
$jednostka = fireStation::create([
|
$jednostka = fireStation::create([
|
||||||
'name' => $request -> unitName,
|
'name' => $request -> fireStationName,
|
||||||
'number' => $request -> number,
|
'number' => $request -> number,
|
||||||
'voivodeship' => $voivodeship -> name,
|
'voivodeship' => $voivodeship -> name,
|
||||||
'county' => $county -> name,
|
'county' => $county -> name,
|
||||||
@ -81,4 +94,60 @@ class fireStationController extends Controller
|
|||||||
|
|
||||||
return redirect()->to('/jednostka');
|
return redirect()->to('/jednostka');
|
||||||
}
|
}
|
||||||
|
public function update(){
|
||||||
|
$this->validate(request(),[
|
||||||
|
'fireStationName' => 'required|min:3|max:45',
|
||||||
|
'number' => 'required|numeric',
|
||||||
|
'voivodeship' => 'required',
|
||||||
|
'county' => 'required',
|
||||||
|
'community' => 'required',
|
||||||
|
'postOffice' => 'required|min:3|max:45',
|
||||||
|
'zipCode' => 'required|digits:5',
|
||||||
|
'latitude' => ['required', 'regex:/^[-]?(([0-8]?[0-9])\.(\d+))|(90(\.0+)?)$/'],
|
||||||
|
'longitude' => ['required', 'regex:/^[-]?((((1[0-7][0-9])|([0-9]?[0-9]))\.(\d+))|180(\.0+)?)$/'],
|
||||||
|
'address' => 'required|min:3|max:45',
|
||||||
|
'KRS' => 'required|digits:10',
|
||||||
|
'NIP' => 'required|digits:10',
|
||||||
|
'phoneNumber' => 'required|digits:9',
|
||||||
|
'email' => 'required|email|unique:fireStations,email,'.auth()->user()->fireStationID, //wymagaj unikalnego adresu email ale pozwól na zachowanie starego adresu
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'required' => ':attribute jest wymagany(e).',
|
||||||
|
'min' => ':attribute musi mieć przynajmniej :min znaki.',
|
||||||
|
'max' => ':attribute musi mieć nie więcej niż :max znaków.',
|
||||||
|
'numeric' => ':attribute może zawierać tylko cyfry.',
|
||||||
|
'digits' => ':attribute musi składać się z :digits cyfr.',
|
||||||
|
'unique' =>':attribute jest już zajęty.',
|
||||||
|
'email' => 'Niepoprawny adres e-mail.',
|
||||||
|
'latitude.regex' =>':attribute ma zakres od -90.0 do 90.0',
|
||||||
|
'longitude.regex' =>':attribute ma zakres od -180.0 do 180.0'
|
||||||
|
]);
|
||||||
|
|
||||||
|
|
||||||
|
$request = request();
|
||||||
|
|
||||||
|
$voivodeship = DB::table('wojewodztwa')->select('name')->where('id', $request -> voivodeship)->first();
|
||||||
|
$county = DB::table('powiaty')->select('name')->where('id', $request -> county)->first();
|
||||||
|
$community = DB::table('gminy')->select('name')->where('id', $request -> community)->first();
|
||||||
|
|
||||||
|
$fireStation = fireStation::find($request->fireStationID);
|
||||||
|
$fireStation-> name = $request-> fireStationName;
|
||||||
|
$fireStation-> number = $request-> number;
|
||||||
|
$fireStation-> voivodeship = $voivodeship-> name;
|
||||||
|
$fireStation-> county = $county-> name;
|
||||||
|
$fireStation-> community = $community-> name;
|
||||||
|
$fireStation-> postOffice = $request-> postOffice;
|
||||||
|
$fireStation-> zipCode = $request-> zipCode;
|
||||||
|
$fireStation-> address = $request-> address;
|
||||||
|
$fireStation-> latitude = $request-> latitude;
|
||||||
|
$fireStation-> longitude = $request-> longitude;
|
||||||
|
$fireStation-> KRS = $request-> KRS;
|
||||||
|
$fireStation-> NIP = $request-> NIP;
|
||||||
|
$fireStation-> phoneNumber = $request-> phoneNumber;
|
||||||
|
$fireStation-> email = $request-> email;
|
||||||
|
$fireStation-> changingID = auth()->user()->id;
|
||||||
|
$fireStation->save();
|
||||||
|
|
||||||
|
return redirect()->to('/jednostka');;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
165
resources/views/fireStationEdit.blade.php
Normal file
165
resources/views/fireStationEdit.blade.php
Normal file
@ -0,0 +1,165 @@
|
|||||||
|
@extends('layout.app')
|
||||||
|
|
||||||
|
@section('center-area')
|
||||||
|
@parent
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<title>Edycja jednostki straży pożarnej</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>Edytuj jednostkę</h2>
|
||||||
|
<form method="POST" action="/jednostka/edit">
|
||||||
|
{{ csrf_field() }}
|
||||||
|
<input type="hidden" class="form-control" name="fireStationID" value="{{ $fireStation->id }}">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="name">Nazwa Jednostki:</label>
|
||||||
|
<input type="text" class="form-control" id="fireStationName" name="fireStationName" value="{{ $fireStation->name }} ">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="name">Numer Jednostki:</label>
|
||||||
|
<input type="text" class="form-control" id="number" name="number" value="{{ $fireStation->number }}">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="voivodeship">Województwo:</label>
|
||||||
|
<select name="voivodeship" class="form-control" style="width:250px">
|
||||||
|
<option value="">--- Wybierz województwo ---</option>
|
||||||
|
@foreach ($voivodeships as $key => $value)
|
||||||
|
<option value="{{ $key }}">{{ $value }}</option>
|
||||||
|
@endforeach
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="county">Powiat:</label>
|
||||||
|
<select name="county" class="form-control"style="width:250px">
|
||||||
|
<option>--Wybierz powiat--</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="community">Gmina:</label>
|
||||||
|
<select name="community" class="form-control"style="width:250px">
|
||||||
|
<option>--Wybierz gminę--</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="name">Urząd Pocztowy:</label>
|
||||||
|
<input type="text" class="form-control" id="postOffice" name="postOffice" value="{{ $fireStation->postOffice }}">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="name">Kod Pocztowy:</label>
|
||||||
|
<input type="text" class="form-control" id="zipCode" name="zipCode" value="{{ $fireStation->zipCode }}">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="name">Ulica:</label>
|
||||||
|
<input type="text" class="form-control" id="address" name="address" value="{{ $fireStation->address }}">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="name">Szerokość Geograficzna:</label>
|
||||||
|
<input type="text" class="form-control" id="latitude" name="latitude" value="{{ $fireStation->latitude }}">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="name">Długość Geograficzna:</label>
|
||||||
|
<input type="text" class="form-control" id="longitude" name="longitude" value="{{ $fireStation->longitude }}">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="name">KRS:</label>
|
||||||
|
<input type="text" class="form-control" id="KRS" name="KRS" value="{{ $fireStation->KRS }}">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="name">NIP:</label>
|
||||||
|
<input type="text" class="form-control" id="NIP" name="NIP" value="{{ $fireStation->NIP }}">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="name">Numer telefonu:</label>
|
||||||
|
<input type="text" class="form-control" id="phoneNumber" name="phoneNumber" value="{{ $fireStation->phoneNumber }}">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="name">Email:</label>
|
||||||
|
<input type="email" class="form-control" id="email" name="email" value="{{ $fireStation->email }}">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<button style="cursor:pointer" type="submit" class="btn btn-primary">Submit</button>
|
||||||
|
</div>
|
||||||
|
@include('inc.formerrors')
|
||||||
|
</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
|
@ -4,7 +4,7 @@
|
|||||||
@parent
|
@parent
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<title>Laravel Dependent Dropdown Tutorial With Example</title>
|
<title>Dodawanie jednostki straży pożarnej</title>
|
||||||
<link rel="stylesheet" href="{{asset('css/app.css')}}">
|
<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">
|
<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>
|
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script>
|
||||||
@ -16,7 +16,7 @@
|
|||||||
{{ csrf_field() }}
|
{{ csrf_field() }}
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="name">Nazwa Jednostki:</label>
|
<label for="name">Nazwa Jednostki:</label>
|
||||||
<input type="text" class="form-control" id="unitName" name="unitName" value="{{ old('unitName') }} ">
|
<input type="text" class="form-control" id="fireStationName" name="fireStationName" value="{{ old('fireStationName') }} ">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
@parent
|
@parent
|
||||||
<ul>
|
<ul>
|
||||||
|
|
||||||
<li>Edytuj<img src="img/left_menu_icon/edit.png"></li>
|
<a href="/jednostka/edit"><li>Edytuj<img src="img/left_menu_icon/edit.png"></li></a>
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
@stop
|
@stop
|
||||||
|
@ -52,6 +52,8 @@ Route::post('/strazacy/edit', 'fireFightersController@update');
|
|||||||
|
|
||||||
Route::get('/jednostka', 'fireStationController@create');
|
Route::get('/jednostka', 'fireStationController@create');
|
||||||
Route::post('/jednostka', 'fireStationController@store');
|
Route::post('/jednostka', 'fireStationController@store');
|
||||||
|
Route::get('/jednostka/edit', 'fireStationController@editForm');
|
||||||
|
Route::post('/jednostka/edit', 'fireStationController@update');
|
||||||
|
|
||||||
Route::get('/jednostka/getcounties/{id}','DataController@getCounties');
|
Route::get('/jednostka/getcounties/{id}','DataController@getCounties');
|
||||||
Route::get('/jednostka/getcommunities/{id}','DataController@getCommunities');
|
Route::get('/jednostka/getcommunities/{id}','DataController@getCommunities');
|
||||||
|
Loading…
Reference in New Issue
Block a user