Snippets

Jenny Rasmussen RSVP Site

Created by Jenny Rasmussen last modified
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class AttendeeCheckController extends Controller
{
    function checkAttendee() {
        $first_name = $_POST['first_name'];
        $last_name = $_POST['last_name'];
        $building_num = $_POST['building_num'];

        $data = DB::table('invites')
            ->join('invites_names AS invite_name_first', function($join){
                $join->on('invites.invite_id', '=', 'invite_name_first.invite_id')
                    ->where('invite_name_first.name_type', '=', 'first');
            })
            ->join('names AS name_first', function($join){
                $join->on('invite_name_first.name_id', '=', 'name_first.name_id');
            })
            ->join('invites_names AS invite_name_last', function($join){
                $join->on('invites.invite_id', '=', 'invite_name_last.invite_id')
                    ->where('invite_name_last.name_type', '=', 'last');
            })
            ->join('names AS name_last', function($join){
                $join->on('invite_name_last.name_id', '=', 'name_last.name_id');
            })
            ->where([['name_first.name_text', '=', $first_name],['name_last.name_text', '=', $last_name],['invites.building_num', '=', $building_num]])
            ->select('invites.invite_id')
            ->get();

        return $data;
    }

    function attendeeRsvp() {
        $first_name = $_POST['first_name'];
        $last_name = $_POST['last_name'];
        $building_num = $_POST['building_num'];
        $rsvp_num = (int)$_POST['rsvp_num'];

        $data = DB::table('invites')
            ->join('invites_names AS invite_name_first', function($join){
                $join->on('invites.invite_id', '=', 'invite_name_first.invite_id')
                    ->where('invite_name_first.name_type', '=', 'first');
            })
            ->join('names AS name_first', function($join){
                $join->on('invite_name_first.name_id', '=', 'name_first.name_id');
            })
            ->join('invites_names AS invite_name_last', function($join){
                $join->on('invites.invite_id', '=', 'invite_name_last.invite_id')
                    ->where('invite_name_last.name_type', '=', 'last');
            })
            ->join('names AS name_last', function($join){
                $join->on('invite_name_last.name_id', '=', 'name_last.name_id');
            })
            ->where([['name_first.name_text', '=', $first_name],['name_last.name_text', '=', $last_name],['invites.building_num', '=', $building_num]])
            ->select('invites.invite_id')
            ->get();

        $result = DB::table('invites')
            ->where([['invite_id', '=', $data->first()->invite_id], ['building_num', '=', $building_num]])
            ->update(['rsvp_num' => $rsvp_num]);

        if ($result === false) {
            return view('try_again');
        }

        if ($rsvp_num === 0) {
            return view('miss_you');
        }

        if($rsvp_num !== 0) {
            return view('thank_you');
        }
    }
}

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.