public function userIsMember($stokvel_id, $user_id) { $isMember = UserStokvel::firstByAttributes(array('stokvel_id' => $stokvel_id, 'user_id' => $user_id)); if ($isMember) { return true; } return false; }
public function generate($id) { $stokvel_users = UserStokvel::where('stokvel_id', '=', $id)->get(); $list = array(); $available_positions = 0; foreach ($stokvel_users as $stokvel_user) { $list[$stokvel_user->user->province_id][] = $stokvel_user->user_id; $available_positions++; } $positions = range(1, $available_positions); //echo "positions -- ".$available_positions; $i = 0; foreach ($list as $province => $province_users) { array_rand($province_users); foreach ($province_users as $index => $user) { if (isset($positions[$i])) { $user_positions[$user] = $positions[$i]; } $i++; } } foreach ($stokvel_users as $stokvel_user) { if (isset($user_positions[$stokvel_user->user_id])) { //$stk = UserStokvel::find($stokvel_user->id); //$stk->position = $user_positions[$stokvel_user->user_id]; //$stk->save(); DB::table('user_stokvels')->where('stokvel_id', $stokvel_user->stokvel_id)->where('user_id', $stokvel_user->user_id)->update(['position' => $user_positions[$stokvel_user->user_id]]); } } DB::table('stokvel')->where('id', $id)->update(['has_payment_order' => TRUE]); Session::flash('message', 'You have successfully generated the stokvel payment order'); return Redirect::to('stokvels/users/' . $id); }
/** * Display a listing of the resource. * * @return Response */ public function index($stokvel_id) { // $stokvel_users = UserStokvel::where('stokvel_id', '=', $stokvel_id)->get(); return view('paymentorder.list', array('stokvel_users' => $stokvel_users)); }