Support the ongoing development of Laravel.io →
Authentication Session Forms

Here is what I have:

 routes.php
 Route::controller('colaboradores', 'ColaboradorController');


 filters.php
 Route::filter('auth.colaboradores', function()
 {
  	 if (Auth::guest()) return Redirect::guest('/colaboradores');
 });


 ColaboradorController.php
 <?php
class ColaboradorController extends BaseController
 {
 
 public function __construct()
 {
    $this->beforeFilter('auth.colaboradores', array('except' => 'getIndex','postIndex'));
}

public function getIndex()
{
	$colaboradores = Colaborador::all();
 	return View::make('full.colaboradores.login');
} 

// pagina principal site/colaboradores autenticação de colaboradores
public function postIndex() {
	if (Auth::attempt(array('login'=>Input::get('login'), 'password'=>Input::get('password')))) {
		return Redirect::to('colaboradores/gerenciar-colaboradores');
	} 
	else 
	{
		return Redirect::to('colaboradores')->with('message', 'Your username/password combination was incorrect')->withInput();
	}		
} 

public function getGerenciarColaboradores()
    {
	   $colaboradores = Colaborador::all();
 	   return View::make('full.colaboradores.index')->with('colaboradores', $colaboradores);
    } 

So I access http://mysite.com/colaboradores and it opens the login page (working fine). Then I anything I type valid or wrong will redirect to http://mysite.com/colaboradores again, instead redirecting http://mysite.com/colaboradores/gerenciar-colaboradores if the credentials are valid.

If I remove the auth filter, everything works fine (it redirects to http://mysite.com/colaboradores/gerenciar-colaboradores if auth OK, or to http://mysite.com/colaboradores if not).

What I'm missing?

Last updated 3 years ago.
0

Your array is not formatted correctly:

$this->beforeFilter('auth.colaboradores', array('except' => 'getIndex','postIndex'));
Array
(
    [except] => getIndex
    [0] => postIndex
)

The following will work:

$this->beforeFilter('auth.colaboradores', array('except' => array('getIndex','postIndex')));
Array
(
    [except] => Array
        (
            [0] => getIndex
            [1] => postIndex
        )

)
Last updated 3 years ago.
0

Thank you. That was exactly that. :)

Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

sytker sytker Joined 29 Apr 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.