2019-09-25 18:39:01 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use App\User;
|
|
|
|
use App\fireStation;
|
|
|
|
use App\Rules\Pesel;
|
2019-10-02 15:26:30 +02:00
|
|
|
use Illuminate\Support\Facades\DB;
|
2019-09-25 18:39:01 +02:00
|
|
|
|
|
|
|
class fireFightersController extends Controller
|
|
|
|
{
|
|
|
|
public function create(){
|
2019-10-02 15:26:30 +02:00
|
|
|
|
|
|
|
if(auth()->user() != null && auth()->user()->fireStationID != null ){
|
2019-10-05 22:29:46 +02:00
|
|
|
// $users = user::where("fireStationID", auth()->user()->fireStationID)->get();
|
|
|
|
$users = DB::table('users')->where("fireStationID", '=', auth()->user()->fireStationID)->get();
|
2019-10-02 15:26:30 +02:00
|
|
|
return view("fireFighters", ["users" => $users]);
|
|
|
|
} else{
|
|
|
|
return view('fireFighters');
|
|
|
|
}
|
|
|
|
|
2019-09-25 18:39:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function addForm(){
|
|
|
|
if(auth()->user() != null && auth()->user()->fireStationID != null ){
|
|
|
|
$fireStation = fireStation::find(auth()->user()->fireStationID);
|
|
|
|
if($fireStation-> creatorID == auth()->user()->id){
|
|
|
|
return view('fireFightersAdd');
|
2019-10-05 23:04:47 +02:00
|
|
|
} else return fireFightersController::create();
|
2019-09-25 18:39:01 +02:00
|
|
|
} else return view("unit");
|
|
|
|
}
|
|
|
|
|
2019-10-05 22:29:46 +02:00
|
|
|
public function editForm($id){
|
|
|
|
if(auth()->user() != null && auth()->user()->fireStationID != null ){
|
|
|
|
$userFireStation = auth()->user()->fireStationID;
|
|
|
|
$fireFighterFireStation = DB::table('users')->where("id", $id)->value('fireStationID');
|
2019-10-06 02:15:16 +02:00
|
|
|
$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]);
|
2019-10-05 22:29:46 +02:00
|
|
|
} else{
|
|
|
|
return "Brak dostepu";
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
return view('unit');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-25 18:39:01 +02:00
|
|
|
public function store(){
|
|
|
|
$this->validate(request(), [
|
|
|
|
|
|
|
|
'name' => 'required|alpha|min:3|max:45',
|
|
|
|
'surname' => 'required|alpha|min:3|max:45',
|
|
|
|
'PESEL' => new Pesel,
|
|
|
|
'phoneNumber' => 'required|digits:9',
|
|
|
|
'email' => 'required|email|unique:users',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'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();
|
|
|
|
$user = User::create([
|
|
|
|
'password' => '123',
|
|
|
|
'email' => $request-> email,
|
|
|
|
'name' => $request-> name,
|
|
|
|
'surname' => $request-> surname,
|
|
|
|
'PESEL' => $request-> PESEL,
|
|
|
|
'phoneNumber' => $request-> phoneNumber,
|
|
|
|
'functionID' => 1,
|
|
|
|
'degreeID' => 1,
|
|
|
|
'number' => 'ABC123',
|
|
|
|
'fireStationID' => auth()->user()->fireStationID,
|
|
|
|
'creatorID' => auth()->user()-> id,
|
|
|
|
'changingID' => auth()->user()-> id
|
|
|
|
]);
|
|
|
|
|
2019-10-05 23:04:47 +02:00
|
|
|
return fireFightersController::create();
|
2019-09-25 18:39:01 +02:00
|
|
|
}
|
2019-10-02 15:26:30 +02:00
|
|
|
|
2019-10-06 02:15:16 +02:00
|
|
|
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();
|
|
|
|
}
|
2019-10-02 15:26:30 +02:00
|
|
|
|
2019-09-25 18:39:01 +02:00
|
|
|
}
|
|
|
|
|