1

Defini uma rota restore no meu arquivo routes.php

<?php

Route::model('user', 'User');
Route::model('comment', 'Comment');
Route::model('post', 'Post');
Route::model('role', 'Role');

Route::resource('upload', 'UploadController');
Route::get('backgroundDefault', 'AdminUsersController@getBackgroundDefault');

Route::group(['prefix' => 'dashboard', 'before' => 'auth'], function()
{
    Route::pattern('user', '[0-9]+');
    Route::pattern('role', '[0-9]+');

    # User Management
    Route::get('manager/users/{user}/show', 'AdminUsersController@getShow');
    Route::get('manager/users/{user}/edit', 'AdminUsersController@getEdit');
    Route::post('manager/users/{user}/edit', 'AdminUsersController@postEdit');
    Route::get('manager/users/{user}/delete', 'AdminUsersController@getDelete');
    Route::get('manager/users/{user}/restore', 'AdminUsersController@getRestore');
    Route::controller('manager/users', 'AdminUsersController');

    # User Role Management
    Route::get('manager/roles/{role}/show', 'AdminRolesController@getShow');
    Route::get('manager/roles/{role}/edit', 'AdminRolesController@getEdit');
    Route::post('manager/roles/{role}/edit', 'AdminRolesController@postEdit');
    Route::get('manager/roles/{role}/delete', 'AdminRolesController@getDelete');
    Route::post('manager/roles/{role}/delete', 'AdminRolesController@postDelete');
    Route::controller('manager/roles', 'AdminRolesController');

    # Optional
    Route::get('faq', 'AdminUsersController@getFaq');
    Route::get('profile', 'AdminUsersController@getProfile');
    Route::get('mural', 'AdminUsersController@getMural');

    # Admin Dashboard
    Route::controller('/', 'AdminDashboardController');
});

Route::group(['prefix' => 'user', 'before' => 'auth'], function()
{
    // User reset routes
    Route::get('reset/{token}', 'UserController@getReset')
    ->where('token', '[0-9a-z]+');
    // User password reset
    Route::post('reset/{token}', 'UserController@postReset')
    ->where('token', '[0-9a-z]+');
    //:: User Account Routes ::
    Route::post('{user}/edit', 'UserController@postEdit')
    ->where('user', '[0-9]+');
});

Route::controller('/', 'UserController');

Route::get('/', ['before' => 'detectLang','uses' => 'UserController@getIndex']);
Route::post('/', ['before' => 'detectLang','uses' => 'UserController@postIndex']);

AdminUsersController, pra nao ficar muito extenso, dei uma resumida removendo alguns metodos

<?php

class AdminUsersController extends AdminController {


    protected $user;

    protected $role;

    protected $permission;

    public function __construct(User $user, Role $role, Permission $permission)
    {
        parent::__construct();
        $this->user = $user;
        $this->role = $role;
        $this->permission = $permission;
    }

    /**
     * Display a listing of the resource.
     *
     * @return Response
     */
    public function getIndex()
    {
        // Title
        $title = Lang::get('admin/users/title.user_management');

        // Show the page
        return View::make('admin.users.index', compact('title'));
    }
...
    public function getDelete($user)
    {
        // checa se usuario logado é o mesmo a ser excluido
        if ($user->id === Confide::user()->id)
        {
            return Redirect::to('dashboard/manager/users')->with('error', Lang::get('admin/users/messages.delete.impossible'));
        }

        //deleta regras
        //AssignedRoles::where('user_id', $user->id)->delete();

        if ($user->delete())
        {
            return Redirect::to('dashboard/manager/users')->with('success', Lang::get('admin/users/messages.delete.success'));
        }
        else
        {
            return Redirect::to('dashboard/manager/users')->with('error', Lang::get('admin/users/messages.delete.error'));
        }
    }

    public function getRestore($user)
    {
        return 'teste';
    }
...

estou acessando o endereço http://intranet.dev/dashboard/manager/users/4/restore

e estou recebendo o erro ExceptionController inserir a descrição da imagem aqui

php artisan routes

+--------+----------------------------------------------------------------------
----------------------+----------------+----------------------------------------
---+----------------+---------------+
| Domain | URI
                      | Name           | Action
   | Before Filters | After Filters |
+--------+----------------------------------------------------------------------
----------------------+----------------+----------------------------------------
---+----------------+---------------+
|        | GET|HEAD upload
                      | upload.index   | UploadController@index
   |                |               |
|        | GET|HEAD upload/create
                      | upload.create  | UploadController@create
   |                |               |
|        | POST upload
                      | upload.store   | UploadController@store
   |                |               |
|        | GET|HEAD upload/{upload}
                      | upload.show    | UploadController@show
   |                |               |
|        | GET|HEAD upload/{upload}/edit
                      | upload.edit    | UploadController@edit
   |                |               |
|        | PUT upload/{upload}
                      | upload.update  | UploadController@update
   |                |               |
|        | PATCH upload/{upload}
                      |                | UploadController@update
   |                |               |
|        | DELETE upload/{upload}
                      | upload.destroy | UploadController@destroy
   |                |               |
|        | GET|HEAD backgroundDefault
                      |                | AdminUsersController@getBackgroundDefau
lt |                |               |
|        | GET|HEAD teste
                      |                | Closure
   |                |               |
|        | GET|HEAD dashboard/manager/users/{user}/show
                      |                | AdminUsersController@getShow
   | auth           |               |
|        | GET|HEAD dashboard/manager/users/{user}/edit
                      |                | AdminUsersController@getEdit
   | auth           |               |
|        | POST dashboard/manager/users/{user}/edit
                      |                | AdminUsersController@postEdit
   | auth           |               |
|        | GET|HEAD dashboard/manager/users/{user}/delete
                      |                | AdminUsersController@getDelete
   | auth           |               |
|        | GET|HEAD dashboard/manager/users/{user}/restore
                      |                | AdminUsersController@getRestore
   | auth           |               |
|        | GET|HEAD dashboard/manager/users/index/{one?}/{two?}/{three?}/{four?}
/{five?}              |                | AdminUsersController@getIndex
   | auth           |               |
|        | GET|HEAD dashboard/manager/users
                      |                | AdminUsersController@getIndex
   | auth           |               |
|        | GET|HEAD dashboard/manager/users/create/{one?}/{two?}/{three?}/{four?
}/{five?}             |                | AdminUsersController@getCreate
   | auth           |               |
|        | POST dashboard/manager/users/create/{one?}/{two?}/{three?}/{four?}/{f
ive?}                 |                | AdminUsersController@postCreate
   | auth           |               |
|        | GET|HEAD dashboard/manager/users/show/{one?}/{two?}/{three?}/{four?}/
{five?}               |                | AdminUsersController@getShow
   | auth           |               |
|        | GET|HEAD dashboard/manager/users/edit/{one?}/{two?}/{three?}/{four?}/
{five?}               |                | AdminUsersController@getEdit
   | auth           |               |
|        | POST dashboard/manager/users/edit/{one?}/{two?}/{three?}/{four?}/{fiv
e?}                   |                | AdminUsersController@postEdit
   | auth           |               |
|        | GET|HEAD dashboard/manager/users/delete/{one?}/{two?}/{three?}/{four?
}/{five?}             |                | AdminUsersController@getDelete
   | auth           |               |
|        | GET|HEAD dashboard/manager/users/restore/{one?}/{two?}/{three?}/{four
?}/{five?}            |                | AdminUsersController@getRestore
   | auth           |               |
|        | GET|HEAD dashboard/manager/users/profile/{one?}/{two?}/{three?}/{four
?}/{five?}            |                | AdminUsersController@getProfile
   | auth           |               |
|        | GET|HEAD dashboard/manager/users/faq/{one?}/{two?}/{three?}/{four?}/{
five?}                |                | AdminUsersController@getFaq
   | auth           |               |
|        | GET|HEAD dashboard/manager/users/mural/{one?}/{two?}/{three?}/{four?}
/{five?}              |                | AdminUsersController@getMural
   | auth           |               |
|        | GET|HEAD dashboard/manager/users/background-default/{one?}/{two?}/{th
ree?}/{four?}/{five?} |                | AdminUsersController@getBackgroundDefau
lt | auth           |               |
|        | GET|HEAD|POST|PUT|PATCH|DELETE dashboard/manager/users/{_missing}
                      |                | AdminUsersController@missingMethod
   | auth           |               |
|        | GET|HEAD dashboard/manager/roles/{role}/show
                      |                | AdminRolesController@getShow
   | auth           |               |
|        | GET|HEAD dashboard/manager/roles/{role}/edit
                      |                | AdminRolesController@getEdit
   | auth           |               |
|        | POST dashboard/manager/roles/{role}/edit
                      |                | AdminRolesController@postEdit
   | auth           |               |
|        | GET|HEAD dashboard/manager/roles/{role}/delete
                      |                | AdminRolesController@getDelete
   | auth           |               |
|        | POST dashboard/manager/roles/{role}/delete
                      |                | AdminRolesController@postDelete
   | auth           |               |
|        | GET|HEAD dashboard/manager/roles/index/{one?}/{two?}/{three?}/{four?}
/{five?}              |                | AdminRolesController@getIndex
   | auth           |               |
|        | GET|HEAD dashboard/manager/roles
                      |                | AdminRolesController@getIndex
   | auth           |               |
|        | GET|HEAD dashboard/manager/roles/create/{one?}/{two?}/{three?}/{four?
}/{five?}             |                | AdminRolesController@getCreate
   | auth           |               |
|        | POST dashboard/manager/roles/create/{one?}/{two?}/{three?}/{four?}/{f
ive?}                 |                | AdminRolesController@postCreate
   | auth           |               |
|        | GET|HEAD dashboard/manager/roles/show/{one?}/{two?}/{three?}/{four?}/
{five?}               |                | AdminRolesController@getShow
   | auth           |               |
|        | GET|HEAD dashboard/manager/roles/edit/{one?}/{two?}/{three?}/{four?}/
{five?}               |                | AdminRolesController@getEdit
   | auth           |               |
|        | POST dashboard/manager/roles/edit/{one?}/{two?}/{three?}/{four?}/{fiv
e?}                   |                | AdminRolesController@postEdit
   | auth           |               |
|        | GET|HEAD dashboard/manager/roles/delete/{one?}/{two?}/{three?}/{four?
}/{five?}             |                | AdminRolesController@getDelete
   | auth           |               |
|        | POST dashboard/manager/roles/delete/{one?}/{two?}/{three?}/{four?}/{f
ive?}                 |                | AdminRolesController@postDelete
   | auth           |               |
|        | GET|HEAD dashboard/manager/roles/data/{one?}/{two?}/{three?}/{four?}/
{five?}               |                | AdminRolesController@getData
   | auth           |               |
|        | GET|HEAD|POST|PUT|PATCH|DELETE dashboard/manager/roles/{_missing}
                      |                | AdminRolesController@missingMethod
   | auth           |               |
|        | GET|HEAD dashboard/faq
                      |                | AdminUsersController@getFaq
   | auth           |               |
|        | GET|HEAD dashboard/profile
                      |                | AdminUsersController@getProfile
   | auth           |               |
|        | GET|HEAD dashboard/mural
                      |                | AdminUsersController@getMural
   | auth           |               |
|        | GET|HEAD dashboard/index/{one?}/{two?}/{three?}/{four?}/{five?}
                      |                | AdminDashboardController@getIndex
   | auth           |               |
|        | GET|HEAD dashboard
                      |                | AdminDashboardController@getIndex
   | auth           |               |
|        | GET|HEAD|POST|PUT|PATCH|DELETE dashboard/{_missing}
                      |                | AdminDashboardController@missingMethod
   | auth           |               |
|        | GET|HEAD user/reset/{token}
                      |                | UserController@getReset
   | auth           |               |
|        | POST user/reset/{token}
                      |                | UserController@postReset
   | auth           |               |
|        | POST user/{user}/edit
                      |                | UserController@postEdit
   | auth           |               |
|        | GET|HEAD create/{one?}/{two?}/{three?}/{four?}/{five?}
                      |                | UserController@getCreate
   |                |               |
|        | GET|HEAD index/{one?}/{two?}/{three?}/{four?}/{five?}
                      |                | UserController@getIndex
   |                |               |
|        | GET|HEAD /
                      |                | UserController@getIndex
   | detectLang     |               |
|        | POST index/{one?}/{two?}/{three?}/{four?}/{five?}
                      |                | UserController@postIndex
   |                |               |
|        | POST /
                      |                | UserController@postIndex
   | detectLang     |               |
|        | GET|HEAD login/{one?}/{two?}/{three?}/{four?}/{five?}
                      |                | UserController@getLogin
   |                |               |
|        | POST login/{one?}/{two?}/{three?}/{four?}/{five?}
                      |                | UserController@postLogin
   |                |               |
|        | GET|HEAD confirm/{one?}/{two?}/{three?}/{four?}/{five?}
                      |                | UserController@getConfirm
   |                |               |
|        | GET|HEAD forgot/{one?}/{two?}/{three?}/{four?}/{five?}
                      |                | UserController@getForgot
   |                |               |
|        | POST forgot/{one?}/{two?}/{three?}/{four?}/{five?}
                      |                | UserController@postForgot
   |                |               |
|        | GET|HEAD reset/{one?}/{two?}/{three?}/{four?}/{five?}
                      |                | UserController@getReset
   |                |               |
|        | POST reset/{one?}/{two?}/{three?}/{four?}/{five?}
                      |                | UserController@postReset
   |                |               |
|        | GET|HEAD logout/{one?}/{two?}/{three?}/{four?}/{five?}
                      |                | UserController@getLogout
   |                |               |
|        | GET|HEAD|POST|PUT|PATCH|DELETE {_missing}
                      |                | UserController@missingMethod
   |                |               |
+--------+----------------------------------------------------------------------
----------------------+----------------+----------------------------------------
---+----------------+---------------+

Todas as rotas acima da restore estão funcionando. Ja tentei retirar minha rota do grupo, alterar o caminho da rota e nome do metodo, mas nada adiantou... não sei mais o que fazer

8
  • 1
    Consegui recriar seu controller e suas rotas numa instalação nova sem problemas. O problema pode estar em algum outro lugar
    – gmsantos
    Commented 19/03/2014 às 22:04
  • Pode postar o resultado do comando php artisan routes ?
    – gmsantos
    Commented 19/03/2014 às 22:18
  • @gmsantos que estranho. Editei o topico acrescentando o comando
    – tiaguinhow
    Commented 20/03/2014 às 11:57
  • O problema pode ser seu arquivo de rotas. Se possível pode colar seu controller e o arquivo de rotas completo para eu tentar reproduzir aqui ?
    – gmsantos
    Commented 20/03/2014 às 12:29
  • Tem certeza que está editando o Controller certo? Está colocando o método em AdminUsersController mesmo? Vai que por acaso você está editando o AdminRolesController sem querer... ?
    – J. Bruni
    Commented 20/03/2014 às 13:18

1 Resposta 1

0

Consegui resolver alterando a nomenclatura do parametro da rota, pois o {user} por padrão estava retornando o objeto da model User

minha rota ficou assim

Route::get('manager/users/{userRestore}/restore', 'AdminUsersController@getRestore');

meu Controller

public function getRestore($id)
    {
        if (User::withTrashed()->where('id', $id)->restore()){
            return Redirect::to('dashboard/manager/users')->with('success', 'Usuario restaurado com sucesso.');
        }else{
            return Redirect::to('dashboard/manager/users')->with('error', 'Não foi possível restaurar o usuario.');
        }
    }

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .