public function run() { DB::table('event_registrations')->delete(); $event_ids = Event::all()->lists('id')->toArray(); $user_ids = User::all()->lists('id')->toArray(); for ($counter = 0; $counter < 50; $counter++) { $rand_event_id = $event_ids[array_rand($event_ids)]; $rand_user_id = $user_ids[array_rand($user_ids)]; if (EventRegistration::where('user_id', '=', $rand_user_id)->where('event_id', '=', $rand_event_id)->exists()) { continue; } EventRegistration::create(array('user_id' => $rand_user_id, 'event_id' => $rand_event_id)); } }
/** * Show the form for creating a new resource. * * @return Response */ public function create() { // TODO Customize checkbox for each registration. $registrations = Registration::where('event_id', session()->get('event_id'))->get(); return view('pages.activities.create', compact('registrations')); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($slug, $id) { $event = Event::findBySlug($slug); if ($id == 'self') { if (\Auth::check()) { EventRegistration::where('user_id', '=', \Auth::id())->where('event_id', '=', $event->id)->delete(); } } else { EventRegistration::destroy($id); } }