/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { $association = Association::findOrFail($id); $association->delete(); return redirect("associations"); }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { $association = Association::findOrFail($id); $association->delete(); \Flash::success('Vereniging verwijderd'); return redirect('admin/associations'); }
public function saveAssociations(Request $request) { $user = Auth::user(); $domain_id = $request->input('domain_id'); $inputs = $request->input('associations'); $main_concept = Concept::find($inputs[0]['concept_id']); // Remove all existing associations for the concept and user Association::where('user_id', $user->id)->where('concept_id', $main_concept->id)->delete(); $associations = array(); foreach ($inputs as $association) { // Adding the entred concepts $concept = Concept::create($association['associated_concept']); // Adding the associations $associations[] = Association::create(['user_id' => $user->id, 'concept_id' => $association['concept_id'], 'weight' => $association['weight'], 'associated_concept_id' => $concept->id]); // Adding the appreciations if exists if (isset($association['associated_concept']['appreciations']) && isset($association['associated_concept']['appreciations'][0])) { Appreciation::create(['user_id' => $user->id, 'concept_id' => $concept->id, 'appreciation' => $association['associated_concept']['appreciations'][0]['appreciation']]); } } // Look if there is an open match $match = Match::where('concept_id', $main_concept->id)->where('user_id', '<>', $user->id)->whereNull('opponent_user_id')->get()->first(); if ($match) { // if there is an open match then close it $match->opponent_user_id = $user->id; $match->save(); } else { // if there is no open match then sorry :( // create a match if (!Match::where('concept_id', $main_concept->id)->where('user_id', $user->id)->whereNull('opponent_user_id')->get()->first()) { // if there is no open match by the same user for the same concept Match::create(['user_id' => $user->id, 'concept_id' => $main_concept->id]); } return Response::json(['flash' => 'No opponent found. your answers will be saved, and you will be notifed when an other player challenges them ;) .', 'nomatch' => true]); } // there is an open match! return Response::json(['match_id' => $match->id]); }