2019-11-17 17:08:02 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use App\vehicle;
|
|
|
|
use DB;
|
|
|
|
use Carbon\Carbon; // formatowanie daty
|
|
|
|
|
|
|
|
function formatDate($date)
|
|
|
|
{
|
2019-12-06 21:22:15 +01:00
|
|
|
if ($date == null)
|
|
|
|
return $date;
|
|
|
|
else
|
|
|
|
$fdate = Carbon::parse($date);
|
|
|
|
return $fdate;
|
2019-11-17 17:08:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
class VehiclesController extends Controller
|
|
|
|
{
|
|
|
|
public function create(){
|
|
|
|
|
|
|
|
if(auth()->user() != null && auth()->user()->fireStationID != null ){
|
|
|
|
$vehicles = DB::table('vehicles')->where("fireStationID", '=', auth()->user()->fireStationID)
|
2019-12-06 21:22:15 +01:00
|
|
|
->whereNull('deleted_at')->get();
|
2019-11-17 17:08:02 +01:00
|
|
|
return view("vehicles", ["vehicles" => $vehicles]);
|
|
|
|
} else{
|
|
|
|
return view('vehicles');
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function addForm(){
|
2019-11-25 01:10:46 +01:00
|
|
|
if(auth()->user() != null && auth()->user()->fireStationID != null ){
|
2019-11-17 17:08:02 +01:00
|
|
|
return view('vehiclesAdd');
|
|
|
|
} else return view("login");
|
|
|
|
}
|
|
|
|
|
|
|
|
public function editForm($id)
|
|
|
|
{
|
|
|
|
if(auth()->user() != null && auth()->user()->fireStationID != null )
|
|
|
|
{
|
2019-11-25 01:10:46 +01:00
|
|
|
|
2019-12-06 21:22:15 +01:00
|
|
|
$vehicle = DB::table('vehicles')->where("id", $id)->first();
|
2019-11-17 17:08:02 +01:00
|
|
|
return view('vehiclesEdit', ["vehicle" => $vehicle]);
|
2019-12-06 21:22:15 +01:00
|
|
|
}
|
2019-11-17 17:08:02 +01:00
|
|
|
else
|
2019-12-06 21:22:15 +01:00
|
|
|
return "Brak dostepu";
|
2019-11-17 17:08:02 +01:00
|
|
|
}
|
2019-11-25 01:10:46 +01:00
|
|
|
|
2019-11-17 17:08:02 +01:00
|
|
|
public function store(){
|
|
|
|
$this->validate(request(), [
|
|
|
|
|
|
|
|
'name' => 'required',
|
2019-12-06 21:22:15 +01:00
|
|
|
'codename' => 'required',
|
|
|
|
'productionYear' => 'digits:4|nullable',
|
|
|
|
'foamAgent' => 'numeric|nullable',
|
|
|
|
'enginePower' => 'numeric|nullable',
|
|
|
|
'crewNumber' => 'numeric|nullable',
|
|
|
|
'mass' => 'numeric|nullable',
|
|
|
|
'chassisPoductionYear' => 'numeric|nullable',
|
2019-11-17 17:08:02 +01:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'required' => ':attribute jest wymagany(e).',
|
|
|
|
'numeric' => ':attribute zawiera tylko cyfry.',
|
|
|
|
'digits' => ':attribute musi składać się z :digits cyfr.',
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
$request = request();
|
|
|
|
$vehicle = vehicle::create([
|
|
|
|
'fireStationID' => auth()->user()->fireStationID,
|
|
|
|
'name' => $request-> name,
|
2019-11-25 01:10:46 +01:00
|
|
|
'codename' => $request-> codename,
|
2019-11-17 17:08:02 +01:00
|
|
|
'brand' => $request-> brand,
|
|
|
|
'registrationNumber' => $request-> registrationNumber,
|
|
|
|
'productionYear' => $request-> productionYear,
|
|
|
|
'examExpirationDate' => formatDate($request-> examExpirationDate),
|
|
|
|
'insuranceExpirationDate' => formatDate($request-> insuranceExpirationDate),
|
|
|
|
'driveType' => $request-> driveType,
|
|
|
|
'chassisType' => $request-> chassisType,
|
|
|
|
'bodyProducer' => $request-> bodyProducer,
|
|
|
|
'crewNumber' => $request-> crewNumber,
|
|
|
|
'foamAgent' => $request-> foamAgent,
|
|
|
|
'enginePower' => $request-> enginePower,
|
|
|
|
'mass' => $request-> mass,
|
|
|
|
'chassisNumber' => $request-> chassisNumber,
|
|
|
|
'engineNumber' => $request-> engineNumber,
|
|
|
|
'fuelType' => $request-> fuelType,
|
|
|
|
'chassisPoductionYear' => $request-> chassisPoductionYear,
|
|
|
|
'entryIntoServiceDate' => formatDate($request-> entryIntoServiceDate),
|
|
|
|
'fireEnginePumpDescription' => $request-> fireEnginePumpDescription,
|
|
|
|
]);
|
|
|
|
|
|
|
|
return redirect()->to('/pojazdy');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function update(){
|
|
|
|
$this->validate(request(), [
|
|
|
|
|
|
|
|
'name' => 'required',
|
2019-12-06 21:22:15 +01:00
|
|
|
'codename' => 'required',
|
|
|
|
'productionYear' => 'digits:4|nullable',
|
|
|
|
'foamAgent' => 'numeric|nullable',
|
|
|
|
'enginePower' => 'numeric|nullable',
|
|
|
|
'crewNumber' => 'numeric|nullable',
|
|
|
|
'mass' => 'numeric|nullable',
|
|
|
|
'chassisPoductionYear' => 'numeric|nullable',
|
2019-11-17 17:08:02 +01:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'required' => ':attribute jest wymagany(e).',
|
|
|
|
'numeric' => ':attribute zawiera tylko cyfry.',
|
|
|
|
'digits' => ':attribute musi składać się z :digits cyfr.',
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
$request = request();
|
|
|
|
$vehicle = vehicle::find( $request->vehicleID);
|
|
|
|
$vehicle-> name = $request-> name;
|
2019-11-25 01:10:46 +01:00
|
|
|
$vehicle-> codename = $request-> codename;
|
2019-11-17 17:08:02 +01:00
|
|
|
$vehicle-> brand = $request-> brand;
|
|
|
|
$vehicle-> registrationNumber = $request-> registrationNumber;
|
|
|
|
$vehicle-> productionYear = $request-> productionYear;
|
|
|
|
$vehicle-> examExpirationDate = formatDate($request-> examExpirationDate);
|
|
|
|
$vehicle-> insuranceExpirationDate = formatDate($request-> insuranceExpirationDate);
|
|
|
|
$vehicle-> driveType = $request-> driveType;
|
|
|
|
$vehicle-> chassisType = $request-> chassisType;
|
|
|
|
$vehicle-> bodyProducer = $request-> bodyProducer;
|
|
|
|
$vehicle-> crewNumber = $request-> crewNumber;
|
|
|
|
$vehicle-> foamAgent = $request-> foamAgent;
|
|
|
|
$vehicle-> enginePower = $request-> enginePower;
|
|
|
|
$vehicle-> mass = $request-> mass;
|
|
|
|
$vehicle-> chassisNumber = $request-> chassisNumber;
|
|
|
|
$vehicle-> engineNumber = $request-> engineNumber;
|
|
|
|
$vehicle-> fuelType = $request-> fuelType;
|
|
|
|
$vehicle-> chassisPoductionYear = $request-> chassisPoductionYear;
|
|
|
|
$vehicle-> entryIntoServiceDate = formatDate($request-> entryIntoServiceDate);
|
|
|
|
$vehicle-> fireEnginePumpDescription = $request-> fireEnginePumpDescription;
|
|
|
|
$vehicle->save();
|
|
|
|
|
2019-12-06 21:22:15 +01:00
|
|
|
return redirect()->to('/pojazdy');;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function destroy($id)
|
|
|
|
{
|
|
|
|
vehicle::where('id',$id)->delete();
|
|
|
|
return redirect()->to('/pojazdy');
|
2019-11-17 17:08:02 +01:00
|
|
|
}
|
|
|
|
}
|