i'have some problems with routing in laravel 4.1
I have a page at url : /AppFastFood/webapp/public/users/profile who work tu edit and update the current user.
i have a page for manage user, index works good at url : /AppFastFood/webapp/public/users
the page to change only the role of the user is/AppFastFood/webapp/public/users/1/edit and it's impossible to show this page, i have the following error : Route [users.updaterole] not defined. (View: C:\wamp\www\AppFastFood\webapp\app\views\users\edit.blade.php)
somebody can help me please ?
here my code : routes.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
routes :