app/Http/Controllers/gCalendarController.php
/**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request $request
     * @return \Illuminate\Http\Response
     */
Store a newly created resource in storage.
Store a newly created resource in storage .
public function store(Request $request)
    {
        $start_date = Carbon::parse($request->start_date)->format('Y-m-d');
        $starttime = date("G:i", strtotime($request->starttime));
        session_start();
        $appointee_id = $request->appointee;
        $appointee = User::find($appointee_id);
        $client = User::where('email', $request->client_email)->first();
        $startDateTime = $start_date. 'T' .$starttime . ':00+06:00';
        $endtime = $dt = Carbon::parse($start_date . ' ' .$starttime. ':00')->addMinutes(30);
        $endDateTime = $start_date. 'T' .$endtime->toTimeString(). '+06:00';
        if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
            $this->client->setAccessToken($_SESSION['access_token']);
            $service = new Google_Service_Calendar($this->client);
            $sendNotifications = array('sendNotifications' => true);
            $calendarId = 'primary';
            $event = new Google_Service_Calendar_Event([
                'summary' => $request->title,
                'description' => $request->description,
                'start' => ['dateTime' => $startDateTime],
                'overrides' => array(
                  array('method' => 'email', 'minutes' => 24 * 60),
                  array('method' => 'popup', 'minutes' => 1),
                ),
                'end' => ['dateTime' => $endDateTime],
                'reminders' => ['useDefault' => true],
                'attendees' => [
                                    [
                                        'email' => $request->client_email, 
                                        'responseStatus' => 'needsAction'
                                    ],
                                    [
                                        'email' => $appointee->email,
                                        'responseStatus' => 'needsAction'
                                    ],
                                ],
                "extendedProperties" =>
                ["private" => ["everyoneDeclinedDismissed" => -1],
                  "useDefault" => true]
            ]);
            $results = $service->events->insert($calendarId, $event, $sendNotifications);
            Appointment::updateOrCreate(
            [
                'title' => $request->title,
                'appointer_id' => $appointee->id,
                'client_id' => $client->id,
            ],
            [
                'title' => $request->title,
                'appointer_id' => $appointee->id,
                'client_id' => $client->id,
                'app_date' => $start_date,
                'app_time' => $starttime,
            ]);
        $appointment = Appointment::where([
                'appointer_id' => $appointee->id,
                'client_id' => $client->id,
                'app_date' => $start_date,
                'app_time' => $starttime,
        ])->first();
        return view('appointment.acknowledgement');
        } else {
            return redirect()->route('oauthCallback');
        }
    }
public function store ( Request $ request ) { $ start_date = Carbon :: parse ( $ request -> start_date ) -> format ( 'Y-m-d' ) ; $ starttime = date ( " G:i " , strtotime ( $ request -> starttime ) ) ; session_start ( ) ; $ appointee_id = $ request -> appointee ; $ appointee = User :: find ( $ appointee_id ) ; $ client = User :: where ( 'email' , $ request -> client_email ) -> first ( ) ; $ startDateTime = $ start_date . 'T' . $ starttime . ':00+06:00' ; $ endtime = $ dt = Carbon :: parse ( $ start_date . ' ' . $ starttime . ':00' ) -> addMinutes ( 30 ) ; $ endDateTime = $ start_date . 'T' . $ endtime -> toTimeString ( ) . '+06:00' ; if ( isset ( $ _SESSION [ 'access_token' ] ) && $ _SESSION [ 'access_token' ] ) { $ this -> client -> setAccessToken ( $ _SESSION [ 'access_token' ] ) ; $ service = new Google_Service_Calendar ( $ this -> client ) ; $ sendNotifications = array ( 'sendNotifications' => true ) ; $ calendarId = 'primary' ; $ event = new Google_Service_Calendar_Event ( [ 'summary' => $ request -> title , 'description' => $ request -> description , 'start' => [ 'dateTime' => $ startDateTime ] , 'overrides' => array ( array ( 'method' => 'email' , 'minutes' => 24 * 60 ) , array ( 'method' => 'popup' , 'minutes' => 1 ) , ) , 'end' => [ 'dateTime' => $ endDateTime ] , 'reminders' => [ 'useDefault' => true ] , 'attendees' => [ [ 'email' => $ request -> client_email , 'responseStatus' => 'needsAction' ] , [ 'email' => $ appointee -> email , 'responseStatus' => 'needsAction' ] , ] , " extendedProperties " => [ " private " => [ " everyoneDeclinedDismissed " => - 1 ] , " useDefault " => true ] ] ) ; $ results = $ service -> events -> insert ( $ calendarId , $ event , $ sendNotifications ) ; Appointment :: updateOrCreate ( [ 'title' => $ request -> title , 'appointer_id' => $ appointee -> id , 'client_id' => $ client -> id , ] , [ 'title' => $ request -> title , 'appointer_id' => $ appointee -> id , 'client_id' => $ client -> id , 'app_date' => $ start_date , 'app_time' => $ starttime , ] ) ; $ appointment = Appointment :: where ( [ 'appointer_id' => $ appointee -> id , 'client_id' => $ client -> id , 'app_date' => $ start_date , 'app_time' => $ starttime , ] ) -> first ( ) ; return view ( 'appointment.acknowledgement' ) ; } else { return redirect ( ) -> route ( 'oauthCallback' ) ; } }
Store a newly created resource in storage.
Store a newly created resource in storage .
// 'sendNotifications' => true, // if ($results) { //     // return response()->json(['status' => 'error', 'message' => 'Something went wrong']); //     // return redirect()->back(); //     return view('appointment.acknowledgement'); // } // return response()->json(['status' => 'success', 'message' => 'Event Created']); // return redirect()->route('email', [$appointee->id, $client->id, $appointment->id]);