user() != null && auth()->user()->fireStationID != null ){ $awardedDecorations = DB::table('decorationsFirefighters')->where("decorationsFirefighters.firefighterID", '=', $id) ->whereNull('decorationsFirefighters.deleted_at') ->leftJoin('decorations', 'decorationsFirefighters.decorationID', '=', 'decorations.id') ->select('decorationName', 'dateOfAward', 'firefighterID', 'decorations.id AS decorationsId', 'decorationsFirefighters.id AS decorationsFirefightersID') ->get(); $alreadyAwarded = $awardedDecorations->pluck('decorationsId')->toArray(); // tablica id wszystkich wyróżnień już posiadanych $firefighter = User::find($id, ['id', 'name', 'surname']); $decoration = DB::table('decorations') ->whereNotIn('id', $alreadyAwarded) //ograniczenie wyboru do wyróżnień jeszcze nie posiadanych ->pluck('decorationName', 'id'); return View::make("decorations") ->with(compact('firefighter')) ->with(compact('awardedDecorations')) ->with(compact('decoration')); } else{ return "Brak dostepu"; } } public function store() { $this->validate(request(),[ 'decoration' => 'required', 'dateOfAward' => 'required', ], [ 'required' => ':attribute jest wymagany(e).', ]); $request = request(); $decoration = decorationsFirefighters::create([ 'firefighterID' => $request-> firefighterID, 'decorationID' => $request-> decoration, 'dateOfAward' => formatDate($request-> dateOfAward), ]); return back(); } public function destroy($id) { decorationsFirefighters::where('id',$id)->delete(); return back(); } }