Laravel5 won't match route edit_user/{id}

107 views Asked by At

please, could you help me a bit?

I have this route in Laravel5:

Route::get('edit_user/{userId}', [
    'as' => 'editUser',
    'uses' => 'Auth\UserController@editUser'
]);

But when I try to go onto url .../edit_user/19 it wont match and redirect me into /home url...

Anyway, when I use this:

Route::get('edit_user/{userId}', [
    'as' => 'editUser',
    function($userId) {
        die($userId);
}
]);

It returns 19.

Here is also my function:

public function editUser($userId) {
    die($userId);
}

Here is also part of my controller:

<?php namespace App\Http\Controllers\Auth;


use App\Models\User;

use Auth;
use Hash;
use Mail;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Session;


class UserController extends Controller {

    /**
     *
     * @return void
     */
    public function __construct()
    {

        $this->middleware('guest', ['except' => 'logout']);
    }


    /**
     *
     * show edit user form
     *
     * @param $id
     */

    public function editUser($userId) {
        die($userId);
    }

Do you know any idea, where might be problem?

Thank you very much for your opinions.

EDIT:

I find out solution -> need to edit exception to auth in __construct.

1

There are 1 answers

1
whoacowboy On

This should work with the code provided.

Check the following items:

1. Do you have this code in the __construct of your UsersController?

public function __construct()
{
    $this->middleware('auth');
}

If so, you need to be lagged in to edit the user.

2. Is there any route listed before edit_user/{userId} that would override this route.

Try moving it to be the very first route.

3. Is you UserController namespaced properly?

<?php 
namespace App\Http\Controllers\Auth;