diff --git a/app/Http/Controllers/fireFightersController.php b/app/Http/Controllers/fireFightersController.php index db0870f..1418fb3 100644 --- a/app/Http/Controllers/fireFightersController.php +++ b/app/Http/Controllers/fireFightersController.php @@ -16,7 +16,6 @@ class fireFightersController extends Controller if(auth()->user() != null && auth()->user()->fireStationID != null ){ // $users = user::where("fireStationID", auth()->user()->fireStationID)->get(); $users = DB::table('users')->where("fireStationID", '=', auth()->user()->fireStationID)->get(); - echo ""; return view("fireFighters", ["users" => $users]); } else{ return view('fireFighters'); @@ -37,8 +36,11 @@ class fireFightersController extends Controller if(auth()->user() != null && auth()->user()->fireStationID != null ){ $userFireStation = auth()->user()->fireStationID; $fireFighterFireStation = DB::table('users')->where("id", $id)->value('fireStationID'); - if($userFireStation == $fireFighterFireStation) { - return view('fireFightersEdit'); + $fireStationCreatorId = DB::table('fireStations')->where("id", $userFireStation)->value('creatorID'); + + $fireFighter = DB::table('users')->where("id", $id)->first(); + if($userFireStation == $fireFighterFireStation && auth()->user()->id == $fireStationCreatorId) { + return view('fireFightersEdit', ["fireFighter" => $fireFighter]); } else{ return "Brak dostepu"; } @@ -88,6 +90,35 @@ class fireFightersController extends Controller return fireFightersController::create(); } + public function update(){ + $this->validate(request(), [ + 'name' => 'required|alpha|min:3|max:45', + 'surname' => 'required|alpha|min:3|max:45', + 'PESEL' => new Pesel, + 'phoneNumber' => 'required|digits:9', + ], + [ + 'required' => ':attribute jest wymagany(e).', + 'min' => ':attribute musi mieć przynajmniej :min znaki.', + 'max' => ':attribute musi mieć nie więcej niż :max znaków.', + 'alpha' => ':attribute może zawierać tylko litery.', + 'alpha_num' => ':attribute może zawierać tylko litery i cyfry.', + 'digits' => ':attribute musi składać się z :digits cyfr.', + 'unique' =>':attribute jest już zajęty.', + 'confirmed' =>':attribute się nie zgadza.', + 'email' => 'Niepoprawny adres e-mail.' + ]); + + $request = request(); + $fireFighter = User::find( $request->userID); + $fireFighter-> name = $request->name; + $fireFighter-> surname = $request->surname; + $fireFighter-> PESEL = $request->PESEL; + $fireFighter-> phoneNumber = $request->phoneNumber; + $fireFighter->save(); + + return fireFightersController::create(); + } } diff --git a/database/migrations/2014_10_12_000000_create_users_table.php b/database/migrations/2014_10_12_000000_create_users_table.php index bd0ae30..c7e1f21 100644 --- a/database/migrations/2014_10_12_000000_create_users_table.php +++ b/database/migrations/2014_10_12_000000_create_users_table.php @@ -4,7 +4,7 @@ use Illuminate\Support\Facades\Schema; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; -class CreateUsersTable extends Migration +class CreateUsersTable extends Migration { /** * Run the migrations. diff --git a/resources/views/fireFighters.blade.php b/resources/views/fireFighters.blade.php index c6d9af5..fbb2230 100644 --- a/resources/views/fireFighters.blade.php +++ b/resources/views/fireFighters.blade.php @@ -49,6 +49,12 @@ document.getElementById("userDegree"+id).style.backgroundColor = "#e6e6e6"; } + + @@ -81,9 +87,17 @@