Linked Questions

Popular Questions

Triggering Javascript Code from PHP Laravel Controller

Asked by At

I'm using OAuth for login in my Laravel Controller. Its working fine but the thing is when the user is registered for the first time, I wanna trigger the HTML 5 geolocation API to fetch the user's current location and do some mixpanel stuff. Earlier I was using AJAX in the JS for the login so there was no such problem but now that I've implemented a complete server side solution, I'm stuck with this one problem.

The Laravel Controller code looks something like this :

       function callback(){
          \\ fetch the access token and graph data
          if($res = \Auth::mjAuthenticate('facebook', $fbData)){                    
                $user = \Auth::scope()->getUser();                          

                return \Redirect::to('events'); 
            if (\Auth::mjRegister('facebook', $fbData)) {

                $user = \Auth::scope()->getUser();                                      

                return \Redirect::to('events');

            return $this->handleFailure('Some Problem Occured');

The Earlier JS Code was :

                .post('auth/login', {
                    data: {
                        oauth_provider: 'facebook',
                        oauth_token: accessToken
                    cache: false
                .done(function(data) {                                              

                    mixpanel.track('User Logged In', {
                        provider: 'Facebook',
                        first_name: data.resource.first_name,
                        last_name: data.resource.last_name
                    if (data.msg == 'Resource registered') {
                      // Prompt for Allow Deny Geolocation popup.

Related Questions