Example #1
0
 public function isUniqueSlug($slug)
 {
     $sheets = Sheet::all();
     foreach ($sheets as $sheet) {
         if ($sheet->slug == $slug) {
             return false;
         }
     }
     return true;
 }
 public function destroy()
 {
     $id = Auth::user()->id;
     $usertodelete = User::find($id);
     $usernotes = DB::table('notes')->where('user_id', $id);
     $allnotes = Note::all();
     $allsheets = Sheet::all();
     $allmeetups = Meetup::all();
     $usermeetups = DB::table('meetups')->where('admin_id', $id);
     $userattending = DB::table('attendees')->where('attendee_id', $id);
     $usercomments = DB::table('meetcoms')->where('attendee_id', $id);
     $usernotecomments = DB::table('notecoms')->where('collaborator_id', $id);
     $usersheetcomments = DB::table('sheetcoms')->where('collaborator_id', $id);
     $sheetids = [];
     $meetupids = [];
     $noteids = [];
     $usercomments->delete();
     $usernotecomments->delete();
     $usersheetcomments->delete();
     // Collects all notes that the user has made
     foreach ($allnotes as $note) {
         if ($note->user_id == $id) {
             array_push($noteids, $note->id);
         }
     }
     // Deletes all collaborators from any notes the user has made
     foreach ($noteids as $notes) {
         $othernotecom = DB::table('notecoms')->where('note_id', $note);
         $othernotecom->delete();
     }
     // Collects all sheets that the user has made
     foreach ($allsheets as $sheet) {
         if ($sheet->user_id == $id) {
             array_push($sheetids, $sheet->id);
         }
     }
     // deletes all lines and collaboration from others in every sheet the user has made
     foreach ($sheetids as $sheets) {
         $userline = DB::table('lines')->where('sheet_id', $sheets);
         $othersheetcom = DB::table('sheetcoms')->where('sheet_id', $sheets);
         $userline->delete();
         $othersheetcom->delete();
     }
     // Collects all meetups that the user is the admin of
     foreach ($allmeetups as $meetup) {
         if ($meetup->admin_id == $id) {
             array_push($meetupids, $meetup->id);
         }
     }
     // Removes all attendees from all meetups that the user is a part of.
     foreach ($meetupids as $meetups) {
         $peopleattending = DB::table('attendees')->where('meetup_id', $meetups);
         $peopleattending->delete();
     }
     $userattending->delete();
     $usernotes->delete();
     $userssheets = DB::table('sheets')->where('user_id', $id);
     $userssheets->delete();
     $usermeetups->delete();
     $usertodelete->delete();
     Session::flash('successMessage', 'Goodbye Forever');
     return Redirect::action('UsersController@showlogin');
 }