我会尽力帮助您翻译。以下是需要翻译的内容:
现在,当我在登录页面点击“使用Facebook登录”时,它会跳转到http://homestead.app/auth/facebook,并显示以下错误信息:
我已经按照http://laravel.com/docs/5.1/authentication中的所有步骤,在Laravel 5.1中使用Facebook进行社交登录。
我已按照以下步骤进行:
1- 在我的Laravel根项目中使用命令:
composer require laravel/socialite
2 - 在您的config/app.php配置文件中注册Laravel\Socialite\SocialiteServiceProvider:
'providers' => [
// Other service providers...
Laravel\Socialite\SocialiteServiceProvider::class,
],
3-在您的应用程序配置文件中将Socialite门面添加到别名数组中:
'Socialite' => Laravel\Socialite\Facades\Socialite::class,
4 - 在config/services.php中添加Facebook服务:
'facebook' => [
'client_id' => env('FACEBOOK_CLIENT_ID'),
'client_secret' => env('FACEBOOK_CLIENT_SECRET'),
'redirect' => 'http://homestead.app/auth/facebook/callback',
],
5 - 在我的AuthController.php中添加redirectToProvider()和handleProviderCallback()方法:
<?php
namespace App\Http\Controllers\Auth;
use App\User;
use Validator;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
use Socialite;
class AuthController extends Controller
{
/*
|--------------------------------------------------------------------------
| Registration & Login Controller
|--------------------------------------------------------------------------
|
| This controller handles the registration of new users, as well as the
| authentication of existing users. By default, this controller uses
| a simple trait to add these behaviors. Why don't you explore it?
|
*/
use AuthenticatesAndRegistersUsers, ThrottlesLogins;
/**
* Redirect path after successful login
*
* @var string
*/
protected $redirectPath = '/greeting';
/**
* Redirect path after failed login
*
* @var string
*/
protected $loginPath = '/auth/login';
/**
* Create a new authentication controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest', ['except' => 'getLogout']);
}
/**
* Get a validator for an incoming registration request.
*
* @param array $data
* @return \Illuminate\Contracts\Validation\Validator
*/
protected function validator(array $data)
{
return Validator::make($data, [
'name' => 'required|max:255',
'email' => 'required|email|max:255|unique:users',
'password' => 'required|confirmed|min:6',
]);
}
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return User
*/
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);
}
/**
* Redirect the user to the Facebook authentication page.
*
* @return Response
*/
public function redirectToProvider()
{
return Socialite::driver('facebook')->redirect();
}
/**
* Obtain the user information from Facebook.
*
* @return Response
*/
public function handleProviderCallback()
{
$user = Socialite::driver('facebook')->user();
dd($user);
}
}
我想强调的是,我已经在文件夹app/Http/Controllers/Auth/中创建了AuthController.php,因为在它要求我们创建路由之后,需要添加以下路由:'Auth\AuthController@redirectToProvider'和'Auth\AuthController@handleProviderCallback'。
6 - 我已经添加了路由:
Route::get('auth/facebook', 'Auth\AuthController@redirectToProvider');
Route::get('auth/facebook/callback', 'Auth\AuthController@handleProviderCallback');
现在,当我在登录页面点击“使用Facebook登录”时,它会跳转到http://homestead.app/auth/facebook,并显示以下错误信息:
我尝试按照指南操作,但该指南适用于 Laravel 5.0(而我需要在 Laravel 5.1 上使用)。FatalErrorException in AuthController.php line 90: Class 'Socialite' not found
bootstrap/cache/services.json
文件,然后运行composer dump-autoload
命令。我曾经遇到过同样的问题,直到有人指出我的 homestead 环境中该文件存在问题。 - Prynz