title: Laravel 4 login facebook
body: <p>A few months ago I created my login with a facebook app. Now that I'm on a new project, I used these routes and the controller (the same as in the previous project) but with a new app for facebook and I had this error</p>
  
  <pre><code>Undefined index: username
  </code></pre>
  
  <p>app/routes.php</p>
  
  <pre><code>Route::get('login/fb', array('as' =&gt; 'facebook.login','uses' =&gt; 'SessionController@facebook'));
  Route::get('login/fb/callback', array('as' =&gt; 'facebook.callback','uses' =&gt; 'SessionController@callback'));
  Route::get('register',array('as' =&gt; 'session.signup','uses' =&gt; 'SessionController@create'));
  Route::get('logout',array('as' =&gt; 'session.logout','uses' =&gt; 'SessionController@destroy'))-&gt;before('auth');
  </code></pre>
  
  <p>app/controllers/SessionController.php</p>
  
  <pre><code>&lt;?php
  
  class SessionController extends BaseController {
  
  public function create()
  {
      return View::make('sessions.create');
  }
  
  public function store()
  {
      $data = array();
  
      if (Auth::check()) {
          $data = Auth::user();
          return Redirect::intended('/profile')-&gt;with('AlertMessage','&lt;p class="alert alert-success"&gt;Has iniciado sesión &lt;strong&gt;correctamente&lt;/strong&gt;&lt;/p&gt;');
      }
  
      return Redirect::intended('/profile')-&gt;with('AlertMessage','&lt;p class="alert alert-danger"&gt;El usuario y/o la contraseña son &lt;strong&gt;incorrectos&lt;/strong&gt;&lt;/p&gt;');
  }
  
  public function show()
  {   
          return View::make('sessions.view');
  }
  
  public function destroy()
  {
      Auth::logout();
  
      return Redirect::to('/')-&gt;with('AlertMessage','&lt;p class="alert alert-info"&gt;Has cerrado sesión &lt;strong&gt;correctamente&lt;/strong&gt;&lt;/p&gt;');
  }
  
  public function callback()
  {
      $code = Input::get('code');
      if (strlen($code) == 0) return Redirect::to('/')-&gt;with('message', 'There was an error communicating with Facebook');
  
      $facebook = new Facebook(Config::get('facebook'));
      $uid = $facebook-&gt;getUser();
  
      if ($uid == 0) return Redirect::to('/')-&gt;with('message', 'There was an error');
  
      $me = $facebook-&gt;api('/me');
  
      $user = User::whereUid($uid)-&gt;first();
      if (empty($user)) {
  
        $user = new User;
        $user-&gt;first_name = $me['first_name'];
        $user-&gt;last_name = $me['last_name'];
        $user-&gt;email = $me['email'];
        $user-&gt;username = $me['username'];
        $user-&gt;uid = $uid;
  
          $user-&gt;save();
      }
  
      $user-&gt;access_token = $facebook-&gt;getAccessToken();
      $user-&gt;save();
  
      Auth::login($user);
  
      return Redirect::to('/')-&gt;with('message', 'Logged in with Facebook');
  }
  
  public function facebook()
  {
      $facebook = new Facebook(Config::get('facebook'));
      $params = array(
          'redirect_uri' =&gt; route('facebook.callback'),
          'scope' =&gt; 'email',
      );
      return Redirect::to($facebook-&gt;getLoginUrl($params));
  }
  }
  </code></pre>
  
  <p>This code works for me with my old facebook app but not with the new app. Any idea the problem? I changed the app_id and secret for the new app, so that there will not the solution.</p>
  
  <p>My 'users' table:</p>
  
  <pre><code>&lt;?php
  
  use Illuminate\Database\Schema\Blueprint;
  use Illuminate\Database\Migrations\Migration;
  
  class CreateUsersTable extends Migration {
  
  public function up()
  {
      Schema::create('users', function(Blueprint $table)
      {
          $table-&gt;increments('id');
          $table-&gt;string('username',100);
          $table-&gt;string('first_name',100)-&gt;nullable();
          $table-&gt;string('last_name',100)-&gt;nullable();
          $table-&gt;string('email',100);
          $table-&gt;biginteger('uid');
          $table-&gt;string('access_token');
          $table-&gt;string('access_toker_secret');
          $table-&gt;text('remember_token',100);
          $table-&gt;string('nickname');
          $table-&gt;timestamps();
  
          $table-&gt;unique('username');
          $table-&gt;unique('email');
  
          $table-&gt;index('username');
          $table-&gt;index('email');
      });
  }
  
  
  public function down()
  {
      Schema::drop('users');
  }
  
  }
  </code></pre>
  
  <p>If I test my old facebook app, my code works normally. Could it be a permissions problem with facebook app?</p>