1

我想通过使用社交身份验证(如 Facebook 身份验证)来创建用户,我遵循了来自 youtube的 Laravel 5.1 中的本教程社交名流身份验证。

使用本教程后,我得到了一个异常,即

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' =>    'abdur.razzaq06@gmail.com', 'password' => '4dbf14f26a97584375b7b2c84b6a4786cb1b4a43'))) in SocialAuthController.php line 84
  at SocialAuthController->create(array('name' => null, 'email' => 'abdur.razzaq06@gmail.com', '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))

我能做些什么来修复它?

这是我的代码:

应用程序\routes.php

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

应用\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');
               }

         }

供应商/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
                }
          }
4

1 回答 1

1

第 84 行调用create控制器的方法。定义了吗?你得到的例外意味着它不是。

create您必须在 SocialAuthController中实际实现该方法

于 2015-09-20T15:19:59.440 回答