user() != null && auth()->user()->fireStationID != null ){ $operations = DB::table('operations')->where('operations.fireStationID', "=", auth()->user()->fireStationID) ->leftJoin('users', 'operations.commanderID', '=', 'users.id') ->select('operations.operationDate', 'operations.location', 'operations.target', 'operations.dangerType', 'operations.description', 'operations.commanderID', 'operations.fireStationID', 'users.id', 'users.name', 'users.surname') ->get(); return view('operation', ["operations" => $operations]); } else{ return view('operation'); } } public function addForm(){ if(auth()->user() != null && auth()->user()->fireStationID != null ){ //$fireStationID = auth()->user()->fireStationID; // $fireFighters = User::pluck('fireStationID', $fireStationID); $fireFighters = DB::table('users')->where("fireStationID", "=", auth()->user()->fireStationID )->get(); $vehicles = DB::table('vehicles')->where("fireStationID", '=', auth()->user()->fireStationID) ->get(); return view("operationAdd", ["fireFighters" => $fireFighters], ["vehicles" => $vehicles]); } else return view("unit"); } public function editForm($id){ if(auth()->user() != null && auth()->user()->fireStationID != null ){ $operation = DB::table('operations')->where('operations.id', '=', $id)->first(); // $operation = DB::table('operations')->where('operations.id', '=', $id) // ->leftJoin('users', 'operations.commanderID', '=', 'users.id') // ->select('operations.id', 'operations.operationDate', 'operations.location', 'operations.target', 'operations.dangerType', 'operations.description', 'operations.commanderID', 'operations.fireStationID', 'users.id', 'users.name', 'users.surname') // ->get(); // if($userFireStation == $fireFighterFireStation && auth()->user()->id == $fireStationCreatorId) { return view('operationEdit', ["operation" => $operation]); // } else{ // return "Brak dostepu"; // } } else{ return view('unit'); } } public function store(){ $this->validate(request(),[ 'operationDate' => 'required', 'operationLocation' => 'required', 'operationTarget' => 'required', 'operationDangerType' => 'required', 'operationDescription' => 'required', 'operationLeader' => 'required', 'operationDriver.*' => 'required', 'operationVehicle.*' => 'required', 'attendance.*' => 'required', 'transport.*' => 'required', ], [ 'required' => ':attribute jest wymagany(e)' ]); $request = request(); $operations = operations::create([ 'operationDate' => $request-> operationDate, 'location' => $request-> operationLocation, 'target' => $request-> operationTarget, 'dangerType' => $request-> operationDangerType, 'description' => $request-> operationDescription, 'commanderID' => $request-> operationLeader, 'fireStationID' => auth()->user()->fireStationID, ]); $operationDriver = $request ->operationDriver; $operationVehicle = $request -> operationVehicle; for($count = 0; $count < count($operationDriver); $count++){ $operationsTrucks = operationsTrucks::create([ 'operationID' => $operations->id, 'truckID' => $operationDriver[$count], 'driverID' => $operationVehicle[$count] ]); } $attendance = $request-> attendance; for($count = 0; $count < count($attendance); $count++){ if($attendance[$count] != 'false'){ $operationsMembers = operationsMembers::create([ 'operationID' => $operations->id, 'memberID' => $attendance[$count], 'privateTransport' => $request->transport[$count], ]); }; } return operationsController::create(); } public function update(){ } }