/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { $currentList = Giftlist::where('list', urldecode($request->listName))->first(); if ($currentList->activation == $request->activationCode) { return $next($request); } return false; }
/** * Pick the names for secret santa * * @param Giftlist $giftlist * @return bool */ public function pickNames(Giftlist $giftlist) { // Find out how many guests are in the draw $guestCount = count($giftlist->guests); // grab the guest list $recipient = $giftlist->guests()->get(); foreach ($giftlist->guests as $giver) { // get the guestid of the current guest $recipientId = $giver->guestid; // increment the guestid, which becomes the recipient of guests gift $recipientId++; // Last guest needs to pick first guest's geustId if ($guestCount == 1) { $recipientId = 0; } // assign receiver to giver $giver->giving_to = $recipient[$recipientId]['guest_name']; $giver->save(); Event::fire(new NameWasDrawn($giver)); // decrement guestCount until there is only one left $guestCount--; } return true; }
/** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) { $gift = Gift::find($id); $lists = Giftlist::lists('name', 'id')->all(); return view('gifts.edit', ['lists' => $lists, 'gift' => $gift]); }
<?php use Carbon\Carbon; use App\Giftlist; /* |-------------------------------------------------------------------------- | Application Routes |-------------------------------------------------------------------------- | | Here is where you can register all of the routes for an application. | It's a breeze. Simply tell Laravel the URIs it should respond to | and give it the controller to call when that URI is requested. | */ Route::get('/', function () { $lists = Giftlist::orderBy('created_at', 'desc')->paginate(10); return view('welcome')->with('lists', $lists); }); //Route::get('admin', function() { // return view('admin'); //}); Route::resource('lists', 'GiftlistsController'); Route::resource('gifts', 'GiftsController'); Route::group(['prefix' => 'admin', 'namespace' => 'Admin'], function () { Route::resource('lists', 'GiftlistsController'); Route::resource('gifts', 'GiftsController'); Route::get('/', function () { return view('admin'); }); }); // Just random testing - not sure how this handles midnight cross-over
/** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show($id) { $list = Giftlist::findOrFail($id); return view('admin.lists.show')->with('list', $list); }
/** * Match givers with receivers and send to email * * @param Request $request * @return \Illuminate\Http\RedirectResponse */ public function postSendList(Request $request) { $giftlist = $this->giftlist->findListByName(urldecode($request->listName)); $this->giftlist->pickNames($giftlist); return view('finished'); }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { if (Giftlist::find($id)->gifts->count() > 0) { return \Redirect::route('lists.index')->with('message', "The list cannot be deleted as it has gifts assigned"); } else { Giftlist::destroy($id); return \Redirect::route('lists.index')->with('message', "The list has been deleted"); } }