Пример #1
0
 /**
  * The users that belong to this group.
  */
 public function participants()
 {
     $participants = collect([]);
     $groupevent = Groupevent::findOrFail($this->id);
     foreach ($groupevent->users as $user) {
         if (!$participants->contains($user)) {
             $participants->push($user);
         }
     }
     return $participants;
 }
Пример #2
0
 /**
  * How much money you owe to the person.
  * @param User::id
  */
 public function owe($receiver_id)
 {
     $toPay = 0;
     $toGetPaid = 0;
     $receiver = User::findOrFail($receiver_id);
     foreach ($receiver->expenses as $expense) {
         $groupevent = Groupevent::findOrFail($expense->groupevent_id);
         if ($groupevent->participants()->contains('id', $this->id) and $groupevent->paid == false) {
             $toPay += $expense->cost / $groupevent->participants()->count();
         }
     }
     foreach ($this->expenses as $expense) {
         $groupevent = Groupevent::findOrFail($expense->groupevent_id);
         if ($groupevent->participants()->contains('id', $receiver->id) and $groupevent->paid == false) {
             $toGetPaid += $expense->cost / $groupevent->participants()->count();
         }
     }
     return $toPay - $toGetPaid;
 }
Пример #3
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $groupevent = Groupevent::findOrFail($id);
     $groupevent->delete();
     return redirect('home');
 }