我想通过Facebook身份验证等社交身份验证来创建用户,我从youtube上学习了这个教程Socialite Authentication in 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 \验证| 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 /框架/ SRC /照亮/路由/ 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
}
}
答案 0 :(得分:1)
第84行调用控制器的create
方法。它定义了吗?你得到的例外意味着它不是。
您必须在SocialAuthController中实际实现create
方法