Exemple #1
0
 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();
     }
 }
Exemple #2
0
 public function run()
 {
     // clear our database ------------------------------------------
     DB::table('bears')->delete();
     DB::table('fish')->delete();
     DB::table('picnics')->delete();
     DB::table('trees')->delete();
     DB::table('bears_picnics')->delete();
     // seed our bears table -----------------------
     // we'll create three different bears
     // bear 1 is named Lawly. She is extremely dangerous. Especially when hungry.
     $bearLawly = App\Bear::create(array('name' => 'Lawly', 'type' => 'Grizzly', 'danger_level' => 8));
     // bear 2 is named Cerms. He has a loud growl but is pretty much harmless.
     $bearCerms = App\Bear::create(array('name' => 'Cerms', 'type' => 'Black', 'danger_level' => 4));
     // bear 3 is named Adobot. He is a polar bear. He drinks vodka.
     $bearAdobot = App\Bear::create(array('name' => 'Adobot', 'type' => 'Polar', 'danger_level' => 3));
     $this->command->info('The bears are alive!');
     // seed our fish table ------------------------
     // our fish wont have names... because theyre going to be eaten
     // we will use the variables we used to create the bears to get their id
     App\Fish::create(array('weight' => 5, 'bear_id' => $bearLawly->id));
     App\Fish::create(array('weight' => 12, 'bear_id' => $bearCerms->id));
     App\Fish::create(array('weight' => 4, 'bear_id' => $bearAdobot->id));
     $this->command->info('They are eating fish!');
     // seed our trees table ---------------------
     App\Tree::create(array('type' => 'Redwood', 'age' => 500, 'bear_id' => $bearLawly->id));
     App\Tree::create(array('type' => 'Oak', 'age' => 400, 'bear_id' => $bearLawly->id));
     $this->command->info('Climb bears! Be free!');
     // seed our picnics table ---------------------
     // we will create one picnic and apply all bears to this one picnic
 }
 /**
  * Test that the user deletion triggers deletion of trees
  *
  * @return void
  */
 public function testUserDeletion()
 {
     $owner = factory(App\User::class)->create();
     $owner_id = $owner->id;
     $this->be($owner);
     factory(App\Tree::class, 2)->create();
     $owner->delete();
     $this->assertTrue(App\Tree::where('user_id', '=', $owner_id)->get()->isEmpty());
 }
 public function run()
 {
     DB::table('users')->delete();
     $user = App\User::create(['name' => 'admin', 'email' => '*****@*****.**', 'created_at' => Carbon\Carbon::now(), 'updated_at' => Carbon\Carbon::now(), 'password' => bcrypt('r2g9R8hJBXazT23g')]);
     Auth::attempt(['email' => '*****@*****.**', 'password' => 'password']);
     App\Tree::create(['title' => 'new tree', 'description' => 'TinyDescription', 'user_id' => $user->id, 'updated_by' => $user->id, 'locked' => 0]);
     App\Tree::create(['title' => 'new tree2', 'description' => 'TinyDescription 2', 'user_id' => $user->id, 'updated_by' => $user->id, 'locked' => 0]);
     App\Tag::create(['title' => 'social engineering', 'slug' => 'social_engineering', 'color' => '#FF0000']);
     $user2 = App\User::create(['name' => 'John Doe', 'email' => '*****@*****.**', 'created_at' => Carbon\Carbon::now(), 'updated_at' => Carbon\Carbon::now(), 'password' => bcrypt('password')]);
     Auth::attempt(['email' => '*****@*****.**', 'password' => 'password']);
     App\Tree::create(['title' => 'new tree3', 'description' => 'TinyDescription 2', 'user_id' => $user2->id, 'updated_by' => $user2->id, 'locked' => 0]);
 }
 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]);
 }