Abdur Razzak
Abdur Razzak

Reputation: 111

Laravel 5.1 BadMethodCallException in Controller.php line 283 Method [create] does not exist

I want to create user by using social authentication like Facebook authentication and I followed this tutorial Socialite Authentication in Laravel 5.1 from youtube.

After using this tutorial I got an Exception which is

BadMethodCallException in Controller.php line 283:
  Method [create] does not exist.

  in Controller.php line 283
  at Controller->__call('create', array(array('name' => null, 'email' =>    '[email protected]', 'password' => '4dbf14f26a97584375b7b2c84b6a4786cb1b4a43'))) in SocialAuthController.php line 84
  at SocialAuthController->create(array('name' => null, 'email' => '[email protected]', 'password' => '4dbf14f26a97584375b7b2c84b6a4786cb1b4a43')) in SocialAuthController.php line 84
  at SocialAuthController->github_Callback()
  at call_user_func_array(array(object(SocialAuthController), 'github_Callback'), array()) in Controller.php line 256
  at Controller->callAction('github_Callback', array()) in ControllerDispatcher.php line 164
  at ControllerDispatcher->call(object(SocialAuthController), object(Route), 'github_Callback') in ControllerDispatcher.php line 112
  at ControllerDispatcher->Illuminate\Routing\{closure}(object(Request))
  at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
  at Pipeline->Illuminate\Pipeline\{closure}(object(Request))

What can I do to fix it?

Here is my code:

app\routes.php

// facebook Sociolite
   Route::get('/auth/facebook', 'Auth\SocialAuthController@redirectToProvider');
   Route::get('callback_facebook', 'Auth\SocialAuthController@handleProviderCallback');

App\Http\Auth|SocialAuthController.php

  <?php

       namespace App\Http\Controllers\Auth;

       use Illuminate\Http\Request;
       use App\Http\Requests;
       use App\Http\Controllers\Controller;
       use Illuminate\Foundation\Auth\ThrottlesLogins;
       use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
       use Illuminate\Foundation\Validation\ValidatesRequests;

       use App\User;
       use Validator;

     //use ValidatesRequests;
       use Socialite;
       use Auth;
       use redirect;

       class SocialAuthController extends Controller
       {   
             // For Facebook
              public function redirectToProvider(){

                     return Socialite::driver('facebook')->redirect();
              }

              public function handleProviderCallback(){

                     $curl = curl_init();
                     curl_setopt($curl , CURLOPT_SSL_VERIFYPEER, false);

                     $user = Socialite::driver('facebook')->user();
                     $data = ['name'=>$user->name, 'email'=>$user->email, 'password'=>$user->token];

                     $userDB = User::where('email',$user->email)->first();


                     if (!is_null($userDB)){
                           Auth::login($userDB);
                     }
                     else{
                          Auth::login($this->create($data)); // line 84
                       // Auth::login($this->data($data));
                     }
               return redirect('/pages/profile');
               }

         }

vendor/laravel/framework/src/Illuminate/Routing/Controller.php

     <?php

          namespace Illuminate\Routing;

          use Closure;
          use BadMethodCallException;
          use Illuminate\Support\Str;
          use InvalidArgumentException;
          use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

          abstract class Controller
          {
                public function __call($method, $parameters)
                {
                       throw new BadMethodCallException("Method [$method] does not exist."); // line 283
                }
          }

Upvotes: 1

Views: 2632

Answers (1)

bernie
bernie

Reputation: 10380

Line 84 calls the create method of your controller. Is it defined? The exception you get implies that it isn't.

You have to actually implement the create method in your SocialAuthController

Upvotes: 1

Related Questions