1
0
forked from s421507/eOSP2
eOSP2/app/Http/Controllers/fireStationController.php

78 lines
2.9 KiB
PHP
Raw Normal View History

2019-09-24 18:05:37 +02:00
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\fireStation;
class fireStationController extends Controller
{
2019-09-25 02:13:13 +02:00
public function create(){
if(auth()->user() != null && auth()->user()->fireStationID != null ){
$fireStation = fireStation::find(auth()->user()->fireStationID);
return view('unit', ["fireStation" => $fireStation]);
} else{
return view('unit');
}
}
2019-09-24 18:05:37 +02:00
public function store()
{
$this->validate(request(),[
'unitName' => 'required|min:3|max:45',
2019-09-25 15:46:57 +02:00
'number' => 'required|numeric',
'voivodeship' => 'required',
'county' => 'required',
'community' => 'required',
2019-09-25 15:46:57 +02:00
'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+)?)$/'],
2019-09-25 15:46:57 +02:00
'address' => 'required|min:3|max:45',
'KRS' => 'required|digits:10',
'NIP' => 'required|digits:10',
'phoneNumber' => 'required|digits:9',
2019-09-28 00:49:15 +02:00
'email' => 'required|email|unique:fireStations',
],
[
'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'
2019-09-24 18:05:37 +02:00
]);
$request = request();
$jednostka = fireStation::create([
'name' => $request -> unitName,
2019-09-24 18:05:37 +02:00
'number' => $request -> number,
'voivodeship' => $request -> voivodeship,
'county' => $request -> county,
'community' => $request -> community,
'postOffice' => $request -> postOffice,
'zipCode' => $request -> zipCode,
'address' => $request -> address,
'latitude' => $request -> latitude,
'longitude' => $request -> longitude,
'KRS' => $request -> KRS,
'NIP' => $request -> NIP,
'phoneNumber' => $request -> phoneNumber,
'email' => $request -> email,
'creatorID' => auth()->user()->id,
'changingID' => auth()->user()->id
]);
$user = auth()->user();
$user->fireStationID = $jednostka->id;
$user->save();
return redirect()->to('/jednostka');
}
}