Маршрут [имя] не определен. Laravel 4.1
У меня есть некоторые проблемы с маршрутизацией в Laravel 4.1
У меня есть страница по адресу: /AppFastFood/webapp/public/users/profile, которая работает для редактирования и обновления текущего пользователя.
У меня есть страница для управления пользователями, индекс хорошо работает по URL: / AppFastFood / webapp / public / users
страница, на которой можно изменить только роль пользователя, - это / AppFastFood / webapp / public / users / 1 / edit, и эту страницу невозможно отобразить. У меня следующая ошибка: Route [users.updaterole] не определен. (Просмотр: C: \ wamp \ www \ AppFastFood \ webapp \ app \ views \ users \ edit.blade.php)
кто-нибудь может мне помочь, пожалуйста?
вот мой код: rout.php
<?php
Route::get('/', function()
{
return Redirect::to('/users/dashboard');
});
//Users
Route::get('users/{all}/edit', 'UsersController@edit');
Route::post('users/{all}', 'UsersController@updaterole');
Route::controller('users', 'UsersController');
//Password
//Route::controller('password', 'RemindersController');
// Routes Users
Route::get('/remind','RemindersController@getRemind');
Route::post('/remind','RemindersController@postRemind');
Route::get('/password/reset/{token}','RemindersController@getReset');
Route::post('/password/reset','RemindersController@postReset');
//requière un login
Route::group(array('before' => 'auth'), function () {
// Routes POI
Route::resource('pois', 'PoiController');
Route::resource('categories', 'CategoryController');
Route::resource('users', 'UsersController');
//Route::resource('users.updaterole', 'UsersController@updaterole');
});
UsersController.php
class UsersController extends BaseController {
//protected $layout = "layouts.main";
public function __construct() {
$this->beforeFilter('csrf', array('on'=>'post'));
$this->beforeFilter('auth', array('only'=>array('getDashboard')));
}
public function edit($id)
{
$user = User::find($id);
$roles = Role::getList(false);
$this->layout->content = View::make('users.edit', array('user' => $user,'roles'=> $roles));
//$this->layout->content = View::make('users.edit')->with('user', $user);
}
public function index()
{
$users = User::all();
// load the view and pass the nerds
$this->layout->content = View::make('users.index')->with('users', $users);
}
public function updaterole($id)
{
// store
/*$user = User::find($id);
$user->fk_role = Input::get('fk_role');
$user->save();
redirect
*/
Session::flash('message', 'Successfully updated user !');
return Redirect::to('users');
//return $this->postUpdate($id);
}
public function getRegister() {
$this->layout->content = View::make('users.register');
}
public function postCreate() {
$validator = Validator::make(Input::all(), User::$rules);
if ($validator->passes()) {
$user = new User;
$user->firstname = Input::get('firstname');
$user->lastname = Input::get('lastname');
$user->username = Input::get('username');
$user->email = Input::get('email');
$user->password = Hash::make(Input::get('password'));
$user->fk_role=3;
$user->save();
return Redirect::to('users/login')->with('message', 'Thanks for registering!');
} else {
return Redirect::to('users/register')->with('message', 'The following errors occurred')->withErrors($validator)->withInput();
}
}
public function getLogin() {
if(Auth::user()){
$this->layout->content = View::make('users.dashboard');
}else{
$this->layout->content = View::make('users.login');
}
}
public function postSignin() {
if (Auth::attempt(array('email'=>Input::get('email'), 'password'=>Input::get('password'))) || Auth::attempt(array('username'=>Input::get('email'), 'password'=>Input::get('password')))) {
return Redirect::to('users/dashboard')->with('message', 'You are now logged in!');
} else {
return Redirect::to('users/login')
->with('message', 'Your username/password combination was incorrect')
->withInput();
}
}
public function getDashboard() {
$this->layout->content = View::make('users.dashboard');
}
public function getLogout() {
Auth::logout();
return Redirect::to('users/login')/* ->with('message', 'Your are now logged out!')*/;
}
public function getRememberToken()
{
return $this->remember_token;
}
public function setRememberToken($value)
{
$this->remember_token = $value;
}
public function getRememberTokenName()
{
return 'remember_token';
}
///update profile
public function getProfile() {
$this->layout->content = View::make('users.profile');
}
public function postUpdate($onlyupdaterole = false) {
$validator = Validator::make(Input::all(), User::$rulesedituser);
if ($validator->passes())
{
$user = User::find(Auth::user()->id);
$currentemail = $user->email;
$user->firstname = Input::get('firstname');
$user->username = Input::get('username');
$user->lastname = Input::get('lastname');
$user->email = Input::get('email');
if(Input::get('password') != NULL)
{
if(Auth::attempt(array('email'=>$currentemail, 'password'=>Input::get('oldpassword'))))
{
$user->password = Hash::make(Input::get('password'));
}
else
{
return Redirect::to('users/profile')->with('alert', 'your actual password is not correct');
}
}
/// vérification que l'email entrée ne pas déjà utilisée.
$existinguser = New User;
// on selectrionne l'utilisateur qui a la même add email que celle entrée.
$existinguser = User::where('email', '=', $user->email)->first();
if ($existinguser != null){
if ($existinguser->id != $user->id) {
return Redirect::to('users/profile')->with('message', 'the e-mail address entered is already in use, please use another one');
}
}
//fin vérif mail
///// vérification que l'username entrée ne pas déjà utilisée.
$existinguser = New User;
// on selectrionne l'utilisateur qui a la même add email que celle entrée.
$existinguser = User::where('username', '=', $user->username)->first();
if ($existinguser != null){
if ($existinguser->id != $user->id) {
return Redirect::to('users/profile')->with('message', 'the username entered is already in use, please use another one');
}
}
//fin verif username
$user->save();
// validation has passed, save user in DB
return Redirect::to('users/dashboard')->with('message', 'Modification OK !');
}
else
{
return Redirect::to('users/profile')->with('message', 'The following errors occurred')->withErrors($validator)->withInput();
}
}
}
?>
edit.blade.php
@section('content')
<h1>Edit {{ $user->firstname }}</h1>
<!-- if there are creation errors, they will show here -->
{{ HTML::ul($errors->all()) }}
{{ Form::model($user, array('route' => array('users.updaterole', $user->id), 'method' => 'PUT')) }}
<div class="form-group">
{{ Form::label('fk_role', 'Role') }}
{{Form::select('fk_role',$roles, $user->fk_role, array('class' => 'form-control')) }}
</div>
{{ Form::submit('Edit the user !', array('class' => 'btn btn-primary')) }}
{{ Form::close() }}
@stop
маршруты:
2 ответа
У вас есть проблемы в ваших объявлениях маршрута. Вы объявили два маршрута, используя один и тот же url
и имя контроллера, как указано ниже:
Route::controller('users', 'UsersController');
Route::resource('users', 'UsersController');
Используйте любой. В вашем php artisan routes
В результате команды нет такого маршрута, который вы использовали в своей форме как действие, вместо этого users.updaterole.update
, Попробуйте использовать любой или переименовать один на другой маршрут и контроллер.
Спасибо, я исправляю свои проблемы с помощью следующих маршрутов:
Route::get('usersadmin/{all}/edit', 'UsersController@edit');
Route::get('usersadmin.update', 'UsersController@update');
Route::post('usersadmin/{all}', 'UsersController@update');