2019-12-06 02:00:06 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use App\equipment;
|
|
|
|
use DB;
|
|
|
|
|
|
|
|
class EquipmentController extends Controller
|
|
|
|
{
|
|
|
|
public function create(){
|
|
|
|
|
|
|
|
if(auth()->user() != null && auth()->user()->fireStationID != null ){
|
|
|
|
$equipment = DB::table('equipment')->where("fireStationID", '=', auth()->user()->fireStationID)
|
2019-12-06 21:22:15 +01:00
|
|
|
->whereNull('deleted_at')->get();
|
2019-12-06 02:00:06 +01:00
|
|
|
return view("equipment", ["equipment" => $equipment]);
|
|
|
|
} else{
|
|
|
|
return view('equipment');
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function addForm(){
|
|
|
|
if(auth()->user() != null && auth()->user()->fireStationID != null ){
|
|
|
|
return view('equipmentAdd');
|
|
|
|
|
|
|
|
} else return view("login");
|
|
|
|
}
|
|
|
|
|
|
|
|
public function editForm($id)
|
|
|
|
{
|
|
|
|
if(auth()->user() != null && auth()->user()->fireStationID != null )
|
|
|
|
{
|
|
|
|
|
|
|
|
$equipment = DB::table('equipment')->where("id", $id)->first();
|
|
|
|
|
|
|
|
return view('equipmentEdit', ["equipment" => $equipment]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return view("login");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function store(){
|
|
|
|
$this->validate(request(), [
|
|
|
|
|
|
|
|
'name' => 'required',
|
|
|
|
'amount' => 'required|numeric',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'required' => ':attribute jest wymagany(a).',
|
|
|
|
'numeric' => ':attribute powinna zawierać tylko cyfry.',
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
$request = request();
|
|
|
|
$equipment = equipment::create([
|
|
|
|
'fireStationID' => auth()->user()->fireStationID,
|
|
|
|
'name' => $request-> name,
|
|
|
|
'amount' => $request-> amount,
|
|
|
|
'parameter' => $request-> parameter,
|
|
|
|
]);
|
|
|
|
|
|
|
|
return redirect()->to('/sprzet');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function update(){
|
|
|
|
$this->validate(request(), [
|
|
|
|
|
|
|
|
'name' => 'required',
|
|
|
|
'amount' => 'required|numeric',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'required' => ':attribute jest wymagany(a).',
|
|
|
|
'numeric' => ':attribute powinna zawierać tylko cyfry.'
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
$request = request();
|
|
|
|
$equipment = equipment::find( $request->equipmentID);
|
|
|
|
$equipment-> name = $request-> name;
|
|
|
|
$equipment-> amount = $request-> amount;
|
|
|
|
$equipment-> parameter = $request-> parameter;
|
|
|
|
$equipment->save();
|
|
|
|
|
2019-12-06 21:22:15 +01:00
|
|
|
return redirect()->to('/sprzet');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function destroy($id)
|
|
|
|
{
|
|
|
|
equipment::where('id',$id)->delete();
|
|
|
|
|
|
|
|
return redirect()->to('/sprzet');
|
2019-12-06 02:00:06 +01:00
|
|
|
}
|
|
|
|
}
|