Exceptioncontroller error on Laravel 4 route

Asked

Viewed 165 times

1

I set a route Restore in my file 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, not to be too extensive, I gave a summary removing some methods

<?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';
    }
...

I’m accessing the address http://intranet.dev/dashboard/manager/users/4/restore

and I’m getting the bug 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
   |                |               |
+--------+----------------------------------------------------------------------
----------------------+----------------+----------------------------------------
---+----------------+---------------+

All routes above the Restore are working. I tried to remove my route from the group, change the route path and method name, but nothing helped... I don’t know what else to do

  • 1

    I was able to recreate your controller and routes in a new installation without problems. The problem may be somewhere else

  • You can post the result of the command php artisan routes ?

  • @gmsantos that strange. I edited the theme adding the command

  • The problem may be your route file. If possible you can paste your controller and the entire route file for me to try playing here ?

  • Are you sure you are editing the right Controller? Are you putting the method in Adminuserscontroller? Will by chance you are editing the Adminrolescontroller unintentionally... ?

  • @gmsantos added the summary controller to the topic. Bruni, I am changing the correct controller rs

  • added the complete route

  • I ended up discovering that it is because the user is deleted in my table - softdelete, deleted_at - that this problem is occurring. Do you know how I can get around this ? And because it happens, the request does not even arrive in my controller ?

Show 3 more comments

1 answer

0


I was able to solve by changing the route parameter nomenclature, because by default {user} was returning the User model object

my route was like this

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

my 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.');
        }
    }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.