Exemplo n.º 1
0
 /**
  * Give trophy to user
  *
  * @param Request $request
  */
 public function postGiveToUser(Request $request)
 {
     $trophy = Trophy::findOrFail($request->trophy);
     $users = [];
     if ($request->users == "" || $request->users == null) {
         return back()->with('error', "Select atleast 1 user")->withInput();
     }
     foreach ($request->users as $user_id) {
         if ($trophy->users->contains($user_id)) {
         } else {
             $users[] = $user_id;
         }
     }
     if ($trophy->max_bearer <= $trophy->users->count()) {
         return back()->with('error', "Trophy already have max_users({$trophy->max_bearer}) in it");
     } else {
         if ($trophy->max_bearer < $trophy->users->count() + count($users)) {
             return back()->with('error', "Trophy don't have enough space in it");
         }
     }
     $trophy->users()->attach($users);
     return back()->with('success', "Trophy awaded to users");
 }
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function show($id)
 {
     $trophy = Trophy::with('conflict', 'subcategory', 'completeness', 'condition')->findOrFail($id);
     return view('trophy.trophy', $trophy);
 }