Параметр маршрутизации Larevel 4.2% 7Busername% 7D не работает

Я делаю небольшой проект с использованием laravel, но по какой-то причине маршрутизация не работает, пожалуйста, укажите мне правильное направление, ниже я публикую код.

маршрутизатор

Route::get('{username}', array('as' => 'profile', 'uses' => 'ProfileController@index'));

контроллер

  public function index($username = null) {
$username = Sentry::getUser()->username;

return View::make('home.profile')
->with('title', 'From controller')
->with('username', $username);

}

Веб-сайт http://social.app/%7Busername%7D

public function postLogin(){
$credentials = Validator::make([
'email' => Input::get('email'),
'password' => Input::get('password')
], [
'email' => 'required|email',
'password' => 'required|alpha_num|between:8,15',
]);
if ($credentials->fails()) {
return Redirect::route('login')
->withInput()
->with('title', 'Welcome to mySite | login')
->withErrors($credentials->getMessageBag());
} else {
try {
$credentials = array(
'email' => Input::has('email') ? Input::get('email') : null,
'password' => Input::has('password') ? Input::get('password') : null,
);

// Log the user in
$user = Sentry::authenticate($credentials, Input::has('remember_me') and Input::get('remember_me') == 'checked');

return View::make('home.profile');
} catch (Cartalyst\Sentry\Users\LoginRequiredException $e) {
return View::make('users.login')
->with('title', 'wrong login')
->with('message', 'Email filed is required');
} catch (Cartalyst\Sentry\Users\PasswordRequiredException $e) {
return View::make('users.login')
->with('title', 'something went wrong')
->with('message', 'Password filed is required');
} catch (Cartalyst\Sentry\Users\WrongPasswordException $e) {
return View::make('users.login')
->with('title', 'wrong Password')
->with('message', 'The password/login is incorrect.');
} catch (Cartalyst\Sentry\Users\UserNotFoundException $e) {
return View::make('users.login')
->with('title', 'Not found')
->with('message', 'Sorry we can't found the user.');
}

}
}

0

Решение

Я до сих пор не вижу перенаправления на profile в вашем контроллере входа, но я думаю, что вы хотите что-то вроде этого:

// ...

$user = Sentry::authenticate($credentials, Input::has('remember_me') and Input::get('remember_me') == 'checked');
return Redirect::route('profile', $user->username);

// ...

Примечание: Имейте в виду, что имя пользователя в качестве URL-адреса корневого уровня означает, что вы должны проверить при создании пользователя, чтобы имя пользователя не вступало в противоречие ни с одним из ваших существующих URL-адресов.

0

Другие решения

Других решений пока нет …