public function addPoints(Request $request, $id) { $this->validate($request, ['amount' => 'required|numeric']); $team = Team::find($id); foreach ($team->users as $user) { $points = new \App\Point(); $points->user_id = $user->id; $points->amount = $request->input('amount'); $points->note = $request->input('note'); $points->save(); } return $this->response(); }
public function sendPoints(Request $request, $id) { $this->validate($request, ['amount' => 'required|numeric']); $recipient = User::find($id); if ($request->user()->points->sum('amount') >= $request->input('amount')) { $points = new \App\Point(); $points->user_id = $request->user()->id; $points->amount = $request->input('amount') * -1; $points->note = "Transfer to {$recipient->name}[{$recipient->id}]."; $points->save(); $senderPoints = new \App\Point(); $senderPoints->user_id = $recipient->id; $senderPoints->amount = $request->input('amount'); $senderPoints->note = "Transfer from {$request->user()->name}[{$request->user()->id}]."; $senderPoints->save(); } return $this->response(); }
<th>Department</th> @foreach($events as $event) <th>{{ $event-> name}}</th> @endforeach <th>Total Points</th> </tr> </thead> <tbody> @foreach ($members as $member) <tr> <td><a href="{{ action('MembersController@show', [$member->id]) }}">{{$member->last_name}}, {{ $member->first_name }}</a></td> <td>{{ $member->department }}</td> @foreach ($events as $event) <?php $member_point = App\Point::where('event_id', $event->id)->where('member_id', $member->id)->first(); ?> @if (is_null($member_point)) <td>0</td> @else <td>{{ $member_point->point }}</td> @endif @endforeach <td>{{ $member->total_points }}</td> <td><a href="{{ action ('PointsController@create', [$member->id]) }}">Add Points</a></td> </tr> @endforeach </tbody> </table> @stop