Reputation: 3221
Im trying to figure out the reason why my controller action is not performing a redirect like intended.
When i click my logout action, it's supposed to terminate a user session and redirect to the home page but it's redirecting to the admin/logout action.
//controller
public function getLogout()
{
Auth::logout();
return Redirect::route('/');
}
//routes
Route::controller('admin', 'AdminController');
Route::controller('/', 'HomeController');
//blade
{{ HTML::linkAction('AdminController@getLogout','Logout') }}
Thanks for your help in advance.
Upvotes: 0
Views: 3378
Reputation: 2655
I think it is because when you are using Redirect::route()
you are supposed to include the route name. See the Laravel API.
Otherwise if you still want to go and redirect to /
without defining its route name. You could instead use Redirect::to()
public function getLogout()
{
Auth::logout();
return Redirect::to('/');
}
Upvotes: 0
Reputation: 3221
The solution is that laravel requires the user table to have a remember_token, which is used to avoid cookie hijacking.
Simply add a nullable 100 character field in your users table called "remember_token" and run the migration.
A good reminder of this would be seen in the default users model because the field is already defined.
Please view link for more information: http://laravel.com/docs/upgrade#upgrade-4.1.26
public function getRememberToken()
{
return $this->remember_token;
}
public function setRememberToken($value)
{
$this->remember_token = $value;
}
public function getRememberTokenName()
{
return 'remember_token';
}
Upvotes: 0
Reputation: 131
Your route:
Route::get('/', array('as' => 'home', 'uses' => 'HomeController@index'));
Then your blade:
{{ link_to_route('home','Home')}}
Upvotes: 1
Reputation: 13
Redirect::to();
and in routes
Route::get('HomeController@getLogut', 'logout');
link like this
<a href="/logout">Logout</a>
Upvotes: 0
Reputation: 4968
Try this:
{{ HTML::linkAction('HomeController@getLogout','Logout') }}
Upvotes: 0
Reputation: 8508
I think you could use named routes :
Route::get('/', array('as' => '/', 'uses' => 'HomeController@index'));
// Replace 'index' with the method you want.
And then in your controller :
return Redirect::route('/');
Or with your current route, this may work :
// Define the route
Route::controller('/', 'HomeController');
// Controller
return Redirect::to('/');
Upvotes: 1