Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

sudipdig's avatar

NotFoundHttpException in RouteCollection.php line 161

I am new in laravel. i am getting following error : NotFoundHttpException in RouteCollection.php line 161: in RouteCollection.php line 161 at RouteCollection->match(object(Request)) in Router.php line 746 at Router->findRoute(object(Request)) in Router.php line 655 at Router->dispatchToRoute(object(Request)) in Router.php line 631 at Router->dispatch(object(Request)) in Kernel.php line 236 at Kernel->Illuminate\Foundation\Http{closure}(object(Request)) at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139 at Pipeline->Illuminate\Pipeline{closure}(object(Request)) in ShareErrorsFromSession.php line 49 at ShareErrorsFromSession->handle(object(Request), object(Closure)) at call_user_func_array(array(object(ShareErrorsFromSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124 at Pipeline->Illuminate\Pipeline{closure}(object(Request)) in StartSession.php line 62 at StartSession->handle(object(Request), object(Closure)) at call_user_func_array(array(object(StartSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124 at Pipeline->Illuminate\Pipeline{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37 at AddQueuedCookiesToResponse->handle(object(Request), object(Closure)) at call_user_func_array(array(object(AddQueuedCookiesToResponse), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124 at Pipeline->Illuminate\Pipeline{closure}(object(Request)) in EncryptCookies.php line 59 at EncryptCookies->handle(object(Request), object(Closure)) at call_user_func_array(array(object(EncryptCookies), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124 at Pipeline->Illuminate\Pipeline{closure}(object(Request)) in CheckForMaintenanceMode.php line 42 at CheckForMaintenanceMode->handle(object(Request), object(Closure)) at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124 at Pipeline->Illuminate\Pipeline{closure}(object(Request)) at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103 at Pipeline->then(object(Closure)) in Kernel.php line 122 at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 87 at Kernel->handle(object(Request)) in index.php line 54

Also i attache my project code. Please help me.

Routes.php

Route::resource('signup','SignupController',['except'=>['create','edit']]);

SignupController.php

namespace App\Http\Controllers;

use Illuminate\Http\Request; use App\Http\Requests; use App\Http\Controllers\Controller; use App\Http\Requests\Signuprequest; use App\AppUser;

class SignupController extends Controller { /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() {

    $app_user=AppUser::all();
    //
    return response()->json($app_user,200);
}

/**
 * Show the form for creating a new resource.
 *
 * @return \Illuminate\Http\Response
 */
public function create()
{
    //
}

/**
 * Store a newly created resource in storage.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return \Illuminate\Http\Response
 */
public function store(Signuprequest $request)
{

    /*  'email' => 'required',
    'password' => 'required',
    'name' => 'required',
    'mobile' => 'required',
    'company' => 'required',
    'designation' => 'required'*/

    $values=$request->only(['email','password','name','mobile','company','designation']);
    
    
   return response()->json(['msg'=>'Signup Successfully'],201);

    //return 'right';
}

/**
 * Display the specified resource.
 *
 * @param  int  $id
 * @return \Illuminate\Http\Response
 */
public function show($id)
{
    //
}

/**
 * Show the form for editing the specified resource.
 *
 * @param  int  $id
 * @return \Illuminate\Http\Response
 */
public function edit($id)
{
    //
}

/**
 * Update the specified resource in storage.
 *
 * @param  \Illuminate\Http\Request  $request
 * @param  int  $id
 * @return \Illuminate\Http\Response
 */
public function update(Request $request, $id)
{
    //
}

/**
 * Remove the specified resource from storage.
 *
 * @param  int  $id
 * @return \Illuminate\Http\Response
 */
public function destroy($id)
{
    //
}

}

Signuprequest.php

namespace App\Http\Requests;

use App\Http\Requests\Request;

class Signuprequest extends Request { /** * Determine if the user is authorized to make this request. * * @return bool */ public function authorize() { return true; }

/**
 * Get the validation rules that apply to the request.
 *
 * @return array
 */
public function rules()
{
    return [
        //
    'email' => 'required',
    'password' => 'required',
    'name' => 'required',
    'mobile' => 'required',
    'company' => 'required',
    'designation' => 'required'

    ];
}

public function response(array $errors)
{
    return response()->json(['msg'=>'please fill all the field','status'=>0]);
}

} AppUser.php

namespace App;

use Illuminate\Database\Eloquent\Model;

class AppUser extends Model { // protected $table = 'app_user'; }

0 likes
21 replies
davorminchorov's avatar

What's your SPA view like (or whatever you use)? When does this error occur?

sudipdig's avatar

when i am call following url in postman

@gmail.com&password=1234&name=Sudip&mobile=9836917092&company=Logicbeanzs&designation=Founder" target="_blank">http://localhost/laravel/public/singup?email=sudipdig@gmail.com&password=1234&name=Sudip&mobile=9836917092&company=Logicbeanzs&designation=Founder

sudipdig's avatar

yes. i call it with post from postman chrom app .

davorminchorov's avatar

write php artisan route:list on the command line and check out your registered routes. I believe that the problem is /laravel/public, it's not attached to the route resource.

Try creating a custom route:

Route::post('/laravel/public/signup', 'SignUpController@store');

and see if that works.

sudipdig's avatar

thanks Ruffles.

after change in route i am getting same problem.

Vytautas's avatar

I had the same error: NotFoundHttpException in RouteCollection.php My problem was in authentication. If user tries to go into mysite.app/admin without signed in it should redirect to login page. For this i used middleware in route.php like this

    Route::get('/admin', [
    'uses'  => '\Mysite\Http\Controllers\AdminController@getAdmin',
    'as'        => 'admin',
    'middleware' => ['auth'],
    ]);

But in App\Http\Middleware\Authenticate.php file there is public function handle, where redirects user if not authenticated to that login page, tho it was

    return redirect()->guest('auth.login');

i just fixed this auth.login to login. But Your structure may be different. So my problem was in authentication redirecting to wrong place

    mysite.app/auth.login

Hope it helps.

zodthepossum's avatar

I'm having the same problem as @sudipdig NotFoundHttpException in RouteCollection.php line 161:

The app will serve up any blade as long as it is not connected to auth

My routes (auth routes taken straight from the docs) & I am following along

Route::get('/', function () {
    return view('welcome');
});

// Authentication routes... added from the docs!
Route::get('auth/login', 'Auth\AuthController@getLogin');
Route::post('auth/login', 'Auth\AuthController@postLogin');
Route::get('auth/logout', 'Auth\AuthController@getLogout');

// Registration routes... added from the docs!
Route::get('auth/register', 'Auth\AuthController@getRegister');
Route::post('auth/register', 'Auth\AuthController@postRegister');

// Password reset link request routes... added from the docs!
Route::get('password/email', 'Auth\PasswordController@getEmail');
Route::post('password/email', 'Auth\PasswordController@postEmail');

// Password reset routes...  added from the docs!
Route::get('password/reset/{token}', 'Auth\PasswordController@getReset');
Route::post('password/reset', 'Auth\PasswordController@postReset');

Route::get('pages/about', 'PagesController@about');
Route::get('pages/contact', 'PagesController@contact');

Route::resource('articles', 'ArticlesController');
Route::resource('auth', 'AuthController');

My AuthController

<?php

namespace App\Http\Controllers\Auth;

use App\User;
use App\Http\Middleware\Authenticate;
use Validator;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;

class AuthController extends Controller
{


    use AuthenticatesAndRegistersUsers, ThrottlesLogins;

        /*
    |--------------------------------------------------------------------------
    | If user is successfully authenticated they will redirected to the articles page
    |--------------------------------------------------------------------------
    |
    */
    protected $redirectPath = '/articles';

    /*
    |--------------------------------------------------------------------------
    | back to login if they did not sucessfully log in, added by me from the docs!dash does not exist!!!!
    |--------------------------------------------------------------------------
    |
    */
    protected $loginPath = '/login';

    /*
    |--------------------------------------------------------------------------
    | Registration & Login Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles the registration of new users, as well as the
    | authentication of existing users. By default, this controller uses
    | a simple trait to add these behaviors. Why don't you explore it?
    |
    */

    /**
     * Create a new authentication controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest', ['except' => 'getLogout']);
    }

    /**
     * Get a validator for an incoming registration request.
     *
     * @param  array  $data
     * @return \Illuminate\Contracts\Validation\Validator
     */
    protected function validator(array $data)
    {
        return Validator::make($data, [
            'firstname' => 'required|max:255',
            'lastname' => 'required|max:255',
            'email' => 'required|email|max:255|unique:users',
            'password' => 'required|confirmed|min:6',
        ]);
    }

    /**
     * Create a new user instance after a valid registration.
     *
     * @param  array  $data
     * @return User
     */
    protected function create(array $data)
    {
        return User::create([
            'firstname' => $data['firstname'],
            'lastname' => $data['lastname'],
            'email' => $data['email'],
            'password' => bcrypt($data['password']),
        ]);
    }
}

My User model

<?php

namespace App;

use Illuminate\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Foundation\Auth\Access\Authorizable;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;

class User extends Model implements AuthenticatableContract, AuthorizableContract, CanResetPasswordContract

{
    use Authenticable, Authorizable, CanResetPassword, HasRoles;
    /**
     * The database table used by the model.
     *
     * @var string
     */
    protected $table = 'users';

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = ['name', 'email', 'password'];

    /**
     * The attributes excluded from the model's JSON form.
     *
     * @var array
     */
    protected $hidden = ['password', 'remember_token'];

    /**
     * A user can have many articles
     *
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */

    public function articles()
    {
        return $this->hasMany('\articles');
    }

}

I've been following along Jeffrey Ways ACL and am really stumped on this

Snapey's avatar

@zodthepossum start your own thread please.

show what route you are calling when the route not found exception occurs

show what your routing table looks like php artisan route:list

zodthepossum's avatar

@snapey I was calling the auth\register routes, because I was trying to add a user.

I finally got my registration page to load and managed to add a user, but only after seeing @Daniel Gutierrez comment (in laravel 5 Fundamentals - I actually did the opposite of what he did, in the registration form (changed from 'auth/register' to '/auth/register' like so {!! Form::open(['url' => '/auth/register', 'method' => 'POST']) !!}

I also changed my routes

Route::get('/auth/register', 'Auth\AuthController@getRegister');
Route::post('/auth/register', 'Auth\AuthController@postRegister');

The above routes show up in php artisan route:list (but for guest! which is confusing)

In my User Model I changed the typo Authenticable to;

use Authenticatable, Authorizable, CanResetPassword;

I also removed the HasRoles trait, and put the following back in the User model

    public function roles()

    {

        return $this->belongsToMany(Role::class);

    }

    public function assignRole($role)

    {
        return $this->roles()->save(

        Role::whereName($role)->firstOrFail()

        );
    }

    public function hasRole($role)

    {
        if (is_string($role)) {

            return $this->roles->contains('name', $role);

        }

        foreach ($role as $r) {

            if ($this->hasRole($r->name)) {

                return true;

            }
        }

    }

However, if I try to add a user via php artisan tinker I'm still getting the following error 'PHP Fatal Error: Class 'App\User' not found in eval()'d code on line 1'

Snapey's avatar

The above routes show up in php artisan route:list (but for guest! which is confusing)

Well if you want to register then you must not have a user account therefore you must not be logged in therefore you are a guest.

If register is not available to guests then who is it for? Certainly not people who are authenticated.

chintan_kapdi's avatar

Laravel routes are case sensitive. Please check your root folder of your website application it should all be all in lower case. Eg:- does not work but works. This might be silly but it solves the issue.

mckneisler's avatar

I was playing around with the registration, login, reset password and request password functions (after I copied the files from the auth directory at https://github.com/bestmomo/scafold/tree/master/views/auth). At one point something I did caused me to start getting this error for any of the routes in the auth path.

I fixed it by deleting all of my cookies for that domain.

Hope this helps!

ulrichm's avatar

in my case it was a deprecated php.ini setting allow_raw_http_post_data or something like that, that gave an error in the returned value, so the script coudn´t read the json array , hence "undefined" I changed the value to -1 and it worked

mindful's avatar

I am still getting the error NotFoundHttpException in RouteCollection.php line 161. my route list displays fine. +--------+----------+--------+---------+------------------------------------------------+------------+ | Domain | Method | URI | Name | Action | Middleware | +--------+----------+--------+---------+------------------------------------------------+------------+ | | GET|HEAD | / | | Closure | web,web | | | POST | signup | /signup | App\Http\Controllers\UserController@postsignup | web,web | +--------+----------+--------+---------+------------------------------------------------+------------+

any ideas @ usama.ashraf ?

jaishree's avatar

I m also getting the same error. Tried all suggestions given by peoples.

Snapey's avatar

@Dyvynh one problem is that you have web middleware listed twice.

Since about 5.2.26 you no longer need to include web middleware in your routes file. Remove it as a first step.

If you still have problems, post your routes.php file and the URL you are trying to access.

@Dyvynh @jaishree post a new thread with your problem and state what does not work and what you are trying. DONT post to a 9 month old thread and expect someone to see it.

secret's avatar

try this one:

php artisan cache:clear

php artisan optimize

php artisan route:cache

php artisan view:clear

php artisan config:cache

Please or to participate in this conversation.