Vladimir
Vladimir

Reputation: 1789

How to set up laravel 5 with facebook

How to set up login with facebook with Laravel 5 I installed php-sdk-v4 and tried something like this:

<?php namespace App\Http\Controllers;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Http\Request;
use FacebookHelper;
use Illuminate\Support\Facades\Config;
use Facebook\FacebookSession;
use Facebook\FacebookRedirectLoginHelper;

class LoginFacebookController extends Controller {
        private $helper;
        public function  _construct(){
            FacebookSession::setDefaultApplication(Config::get('facebook.app_id'), Config::get('facebook.app_secret'));
            $this-> helper = new FacebookRedirectLoginHelper(url('login/fb/callback'));

        }

        public function getUrlLogin(){

            return $this -> helper->getLoginUrl(Config::get('facebook.app_scope'));
        }

    public function login(){

            return Redirect::to(self::getUrlLogin());
        }



        public function callback(){

            dd(Input::all());
        }
}

But get this error:

FatalErrorException in LoginFacebookController.php line 23: Call to a member function getLoginUrl() on a non-object

Any solution?

Upvotes: 0

Views: 3322

Answers (2)

Habeebullah Saheb
Habeebullah Saheb

Reputation: 11

Run these commands:

apt-get install php5-curl
composer update

Then, add the class in your providers and the Socialite alias in your aliases.

Upvotes: 0

Elias
Elias

Reputation: 1560

Laravel 5 introduces the first-party Socialite package which includes support for Facebook. The documentation has more information on how to set it up but in the end, the code required to interact with Facebook is much easier:

$user = Socialize::with('facebook')->user();

Upvotes: 1

Related Questions