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?
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
)
)
Thank you. That was exactly that. :)
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community