私はhttp://laravel.com/docs/5.1/authenticationのすべてのステップを踏んで、Laravel 5.1のFacebookでソーシャルログインを行いました。ここでLaravelでのFacebook Socialiteのログイン5.1
私が続いてきたのステップ:
1 - 私のLaravelのルートプロジェクト内のコマンドを使用します。
composer require laravel/socialite
2 - あなたのconfig /アプリでLaravel \名士\ SocialiteServiceProviderを登録します。 PHPの設定ファイル:
'providers' => [
// Other service providers...
Laravel\Socialite\SocialiteServiceProvider::class,
],
3 - アプリの設定ファイルのエイリアスアレイに名士のファサードを追加します。
'Socialite' => Laravel\Socialite\Facades\Socialite::class,
4 - 設定でFacebookのサービスを追加/ services.php:
'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);
}
}
「Auth \ AuthController @ redirectToProvider ' ' Auth \ AuthController @ handleProviderCallbacというルートを作成するように頼んだので、私は、アプリケーション/ Http/Controllers/Auth /フォルダにAuthController.phpを作成したことを強調したいと思います。 K」
6 - 私はルートを追加しました:
今Route::get('auth/facebook', 'Auth\[email protected]');
Route::get('auth/facebook/callback', 'Auth\[email protected]');
、私はそれがhttp://homestead.app/auth/facebookに行く私のログインページに 『facebookでログイン』をクリックして、私は次のエラーを取得する場合:
をFatalErrorException in AuthController.php line 90: Class 'Socialite' not found
私はcodeanchor guideに従うことを試みたが、それはlaravel 5.0用です。最後に私が解決した
作曲家に「composer dump-autoload」を使ってみてください – aldrin27
私はちょうど試しましたが、何も変わっていません – Finn87
ホームステッドデータベースを使っていますか?またはローカルですか? – aldrin27