public function rank($slot) { if (\App\Ranking::where('slot_code', '=', $slot->slot_code)->exists() == false) { $rank = new \App\Ranking(); $rank->slot_code = $slot->slot_code; $rank->user_id = $slot->user_id; $rank->save(); $rank->slot_rank = $rank->id; $rank->slot_exit = 0; $rank->save(); $tv1 = $rank->id; $tv2 = $rank->id * 2; $tv3 = $tv2 * 2; $tree = new \App\Tree(); $tree->down1 = $tv2; $tree->down2 = $tv2 + 1; $tree->down3 = $tv3; $tree->down4 = $tv3 + 1; $tree->down5 = $tv3 + 2; $tree->down6 = $tv3 + 3; $tree->save(); $rank->tree_id = $tree->id; $rank->save(); } }
public function create() { $data = \Input::all(); if ($data['transaction_number'] != '') { $amount_slot = $data['amount'] / 500; $transaction = new \App\Transaction(); $transaction->transaction_number = $data['transaction_number']; $transaction->amount = $data['amount']; $transaction->save(); $stat_id = 4; } else { $amount_slot = $data['amount'] / 500; $transaction = new \App\Transaction(); $transaction->transaction_number = 'No Payment'; $transaction->amount = 0; $transaction->save(); $stat_id = 2; } $check = \Auth::User()->name . '' . Carbon::now(); $user = \Auth::User(); $limit = $user->limit; // dd($limit); if ($data['num_slots'] > $limit) { for ($i = 0; $i < $limit; $i++) { if ($i < $amount_slot) { $slot = new \App\Slot(); $slot->slot_code = str_random(15); $slot->slot_rank = 0; $slot->user_id = \Auth::User()->id; $transaction->slots()->save($slot); $status = \App\Status::find($stat_id); $status->slots()->attach($slot); $user = \Auth::User(); $user->limit = $user->limit - 1; $user->save(); $tree = new \App\Tree(); $tree->down1 = $slot->id - 1; $tree->down2 = $slot->id - 2; $tree->down3 = $slot->id - 3; $tree->down4 = $slot->id - 4; $tree->down5 = $slot->id - 5; $tree->down6 = $slot->id - 6; $tree->save(); $slot->tree_id = $tree->id; $slot->save(); } else { $slot = new \App\Slot(); $slot->slot_code = str_random(15); $slot->slot_rank = 0; $slot->user_id = \Auth::User()->id; $slot->save(); $status = \App\Status::find(2); $status->slots()->attach($slot); $user = \Auth::User(); $user->limit = $user->limit - 1; $user->save(); $tree = new \App\Tree(); $tree->down1 = $slot->id - 1; $tree->down2 = $slot->id - 2; $tree->down3 = $slot->id - 3; $tree->down4 = $slot->id - 4; $tree->down5 = $slot->id - 5; $tree->down6 = $slot->id - 6; $tree->save(); $slot->tree_id = $tree->id; $slot->save(); } } } else { for ($i = 0; $i < $data['num_slots']; $i++) { if ($i < $amount_slot) { $slot = new \App\Slot(); $slot->slot_code = str_random(15); $slot->slot_rank = 0; $slot->user_id = \Auth::User()->id; $transaction->slots()->save($slot); $status = \App\Status::find($stat_id); $status->slots()->attach($slot); $user = \Auth::User(); $user->limit = $user->limit - 1; $user->save(); $tree = new \App\Tree(); $tree->down1 = $slot->id - 1; $tree->down2 = $slot->id - 2; $tree->down3 = $slot->id - 3; $tree->down4 = $slot->id - 4; $tree->down5 = $slot->id - 5; $tree->down6 = $slot->id - 6; $tree->save(); $slot->tree_id = $tree->id; $slot->save(); } else { $slot = new \App\Slot(); $slot->slot_code = str_random(15); $slot->slot_rank = 0; $slot->user_id = \Auth::User()->id; $slot->save(); $status = \App\Status::find(2); $status->slots()->attach($slot); $user = \Auth::User(); $user->limit = $user->limit - 1; $user->save(); $tree = new \App\Tree(); $tree->down1 = $slot->id + 1; $tree->down2 = $slot->id + 2; $tree->down3 = $slot->id + 3; $tree->down4 = $slot->id + 4; $tree->down5 = $slot->id + 5; $tree->down6 = $slot->id + 6; $tree->save(); $slot->tree_id = $tree->id; $slot->save(); } } } $user = \Auth::User(); $ranks = 0; $slots = $user->slots()->get(); return view('dashboard.user.profile')->with(['slots' => $slots, 'num_slots' => $data['num_slots'], 'limit' => $limit, 'user' => $user, 'ranks' => $ranks]); }