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)
|
2020-01-29 01:57:19 +01:00
|
|
|
->whereNull('deleted_at')->paginate(10);
|
2019-12-06 02:00:06 +01:00
|
|
|
return view("equipment", ["equipment" => $equipment]);
|
|
|
|
} else{
|
|
|
|
return view('equipment');
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function addForm(){
|
2020-02-01 01:01:26 +01:00
|
|
|
if(auth()->user() != null && auth()->user()->accessLevel() == 50 ){ //prezes,naczelnik
|
2019-12-06 02:00:06 +01:00
|
|
|
return view('equipmentAdd');
|
2020-01-29 01:57:19 +01:00
|
|
|
|
2020-02-01 01:01:26 +01:00
|
|
|
} else return redirect()->to('/sprzet');
|
2019-12-06 02:00:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function editForm($id)
|
|
|
|
{
|
2020-02-01 01:01:26 +01:00
|
|
|
if(auth()->user() != null && auth()->user()->accessLevel() == 50 ) //prezes,naczelnik
|
2019-12-06 02:00:06 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
$equipment = DB::table('equipment')->where("id", $id)->first();
|
2020-01-29 01:57:19 +01:00
|
|
|
|
2019-12-06 02:00:06 +01:00
|
|
|
return view('equipmentEdit', ["equipment" => $equipment]);
|
2020-01-29 01:57:19 +01:00
|
|
|
}
|
2019-12-06 02:00:06 +01:00
|
|
|
else
|
2020-02-01 01:01:26 +01:00
|
|
|
return redirect()->to('/sprzet');
|
2020-01-29 01:57:19 +01:00
|
|
|
|
2019-12-06 02:00:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function store(){
|
|
|
|
$this->validate(request(), [
|
|
|
|
|
2020-01-31 03:13:13 +01:00
|
|
|
'name' => 'required|max:45',
|
|
|
|
'amount' => 'required|numeric|digits_between:1,10',
|
|
|
|
'parameter' => 'max:45|nullable',
|
2019-12-06 02:00:06 +01:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'required' => ':attribute jest wymagany(a).',
|
2020-01-31 03:13:13 +01:00
|
|
|
'name.required' => 'nazwa jest wymagany(a).',
|
|
|
|
'name.max' => 'nazwa musi mieć nie więcej niż :max znaków.',
|
|
|
|
'max' => ':attribute musi mieć nie więcej niż :max znaków.',
|
2019-12-06 02:00:06 +01:00
|
|
|
'numeric' => ':attribute powinna zawierać tylko cyfry.',
|
2020-01-31 03:13:13 +01:00
|
|
|
'digits_between' => ':attribute jest za duży(a)'
|
2019-12-06 02:00:06 +01:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
$request = request();
|
|
|
|
$equipment = equipment::create([
|
|
|
|
'fireStationID' => auth()->user()->fireStationID,
|
|
|
|
'name' => $request-> name,
|
2020-01-29 01:57:19 +01:00
|
|
|
'amount' => $request-> amount,
|
2019-12-06 02:00:06 +01:00
|
|
|
'parameter' => $request-> parameter,
|
|
|
|
]);
|
|
|
|
|
|
|
|
return redirect()->to('/sprzet');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function update(){
|
|
|
|
$this->validate(request(), [
|
|
|
|
|
2020-01-31 03:13:13 +01:00
|
|
|
'name' => 'required|max:45',
|
|
|
|
'amount' => 'required|numeric|digits_between:1,10',
|
|
|
|
'parameter' => 'max:45|nullable',
|
2019-12-06 02:00:06 +01:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'required' => ':attribute jest wymagany(a).',
|
2020-01-31 03:13:13 +01:00
|
|
|
'name.required' => 'nazwa jest wymagany(a).',
|
|
|
|
'name.max' => 'nazwa musi mieć nie więcej niż :max znaków.',
|
|
|
|
'max' => ':attribute musi mieć nie więcej niż :max znaków.',
|
|
|
|
'numeric' => ':attribute powinna zawierać tylko cyfry.',
|
|
|
|
'digits_between' => ':attribute jest za duży(a)'
|
2019-12-06 02:00:06 +01:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
$request = request();
|
|
|
|
$equipment = equipment::find( $request->equipmentID);
|
|
|
|
$equipment-> name = $request-> name;
|
2020-01-29 01:57:19 +01:00
|
|
|
$equipment-> amount = $request-> amount;
|
2019-12-06 02:00:06 +01:00
|
|
|
$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();
|
2020-01-29 01:57:19 +01:00
|
|
|
|
|
|
|
return response()->json([
|
|
|
|
'success' => 'Record deleted successfully!'
|
|
|
|
]);
|
2019-12-06 02:00:06 +01:00
|
|
|
}
|
|
|
|
}
|