/**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     //check that the models work
     $escape_id = \App\Escape::where('name', '=', 'Great Barrier Reef')->pluck('id');
     $holiday_id = \App\Holiday::where('name', '=', 'holiday in Cairns')->pluck('id');
     DB::table('escape_holiday')->insert(['created_at' => Carbon\Carbon::now()->toDateTimeString(), 'updated_at' => Carbon\Carbon::now()->toDateTimeString(), 'escape_id' => $escape_id, 'holiday_id' => $holiday_id]);
     $escape_id = \App\Escape::where('name', '=', 'Bondi Beach')->pluck('id');
     $holiday_id = \App\Holiday::where('name', '=', 'holiday in Sydney')->pluck('id');
     DB::table('escape_holiday')->insert(['created_at' => Carbon\Carbon::now()->toDateTimeString(), 'updated_at' => Carbon\Carbon::now()->toDateTimeString(), 'escape_id' => $escape_id, 'holiday_id' => $holiday_id]);
     $escape_id = \App\Escape::where('name', '=', 'cuddle Koalas')->pluck('id');
     $holiday_id = \App\Holiday::where('name', '=', 'Australian tour')->pluck('id');
     DB::table('escape_holiday')->insert(['created_at' => Carbon\Carbon::now()->toDateTimeString(), 'updated_at' => Carbon\Carbon::now()->toDateTimeString(), 'escape_id' => $escape_id, 'holiday_id' => $holiday_id]);
     $escape_id = \App\Escape::where('name', '=', 'Pebbly Beach')->pluck('id');
     $holiday_id = \App\Holiday::where('name', '=', 'holiday in Sydney')->pluck('id');
     DB::table('escape_holiday')->insert(['created_at' => Carbon\Carbon::now()->toDateTimeString(), 'updated_at' => Carbon\Carbon::now()->toDateTimeString(), 'escape_id' => $escape_id, 'holiday_id' => $holiday_id]);
     $escape_id = \App\Escape::where('name', '=', 'hartlies crocodile adventures')->pluck('id');
     $holiday_id = \App\Holiday::where('name', '=', 'holiday in Cairns')->pluck('id');
     DB::table('escape_holiday')->insert(['created_at' => Carbon\Carbon::now()->toDateTimeString(), 'updated_at' => Carbon\Carbon::now()->toDateTimeString(), 'escape_id' => $escape_id, 'holiday_id' => $holiday_id]);
 }
示例#2
0
 public function postDelete(Request $request)
 {
     $logged_in_user = \Auth::user();
     //find the user that is logged in
     $holiday_mod = \App\Holiday::find($request->id);
     //get the holiday from the DB
     $holidayToDelete = \App\Holiday::with('escapes')->where('id', '=', $request->id)->get();
     //get the holiday and the escapes
     $holiday_mod->escapes()->sync([]);
     //remove the escapes from the pivot table escape_holiday
     $holiday_mod->delete();
     //delete the holiday
     //iterate over the escapes and delete them from the escape table
     foreach ($holidayToDelete[0]['escapes'] as $escape) {
         $escapeToDelete = \App\Escape::find($escape->id);
         $escapeToDelete->delete();
     }
     //send the user back to the holiday create page
     return redirect('holiday/create');
 }
示例#3
0
 public function postDelete(Request $request)
 {
     //gets the holiday that the escape belongs to
     $holiday = \App\Holiday::find($request->holiday_id);
     //loads the escape to be delete
     $escapeToDelete = \App\Escape::find($request->id);
     //detaches the escape from the holiday
     $holiday->escapes()->detach($request->id);
     //deletes the escape
     $escapeToDelete->delete();
     //load the holiday with its escapes
     $holidayWithEscapes = \App\Holiday::with('escapes')->where('id', '=', $request->holiday_id)->get();
     return redirect('holiday/create');
 }