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

Garofano's avatar

How do i get a clue to which controller/action is route resolved to

Hi,

I have rather large app and now i am lost with one route. I have this route defined as GET in routes.php, but when i send post to this route i get redirect back. And i can find where is this redirect coming, i would like to know to which controller / action is this POST route resolved to and i dont know how? Its not listed in my routes.php, but still it exists.

Anyone?

Thank you.

0 likes
12 replies
rodrigo.pedra's avatar

Run

php artisan route:list

on your terminal/shell. This command will show all registered routes and its associated controller methods, middleware, etc.

Be aware that if two routes have the same name (defined with the as option) and the same HTTP method (GET, POST, etc.) Laravel will keep only the last defined one.

Garofano's avatar

This route isnt listed in "php artisan route:list" yet still is working and not throwing 404. I dont think its middleware.

The question is how to easily debug this? I dont even know controller responsible for this route. If i would find controller i would find an action easily by getActionName()

willvincent's avatar

Do you have any kind of wildcard route? That might be picking it up if so.

It would probably be helpful to see the output of php artisan route:list along with you telling us the specific route that's giving you issues.

rodrigo.pedra's avatar

Write a middleware that logs all the requests and add it at the end of default the middleware stack.

<?php
// app/Http/Middleware/RequestLogger.php

namespace App\Http\Middleware;

use Closure;

class RequestLogger
{
    public function handle( $request, Closure $next )
    {
        \Log::debug( 'LOGGING REQUEST', [ $request ] );

        $response = $next( $request );

        \Log::debug( 'LOGGING RESPONSE', [ $response ] );

        return $response;
    }
}

and in your app/Http/Kernel.php file:

// assuming Laravel 5.2

// ...
    protected $middleware = [
        \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
       // any other middlewares ...
        App\Http\Middleware\RequestLogger::class,
    ];

// ...

Then check the end of your log file for the debug info. Of course you can log just the relevant information like $request->path(), $request->route()->getName() to trim the ouput.

3 likes
feeela's avatar

@rodrigo.pedra Sadly this dos not log anything. Do I have to activate that RequestLogger somewhere (besides app/HTTP/Kernel.php)? Or do I have to change the log levels manually in config/logging.php? (There the "level" entries are mostly set to "error" – is that a minimum or maximum error type?)

Thanks from someone who is new to Laravel.

Garofano's avatar

This is getting weird. I have just tried to change the route but it is not working either. See route:list

POST     | account/manage-agency/save-settings               | account/manage-agency/save-settings   | App\Http\Controllers\AccountController@agencySettingsSave

And Im getting MethodNotAllowedHttpException on POST to /account/manage-agency/save-settings (at RouteCollection->methodNotAllowed(array('POST')))

Because it will first hit the page with POST and then redirect with GET to the same page.

rodrigo.pedra's avatar

weird... Check if the form does not have any field named _method. I don't know what else I can suggest to help you, I'm sorry.

Garofano's avatar

The route is redirected before it will hit the middleware where i am loggin the requests. But with other requests everything is ok.

Garofano's avatar

Ok, i have found it. The problem was that i have forgot csrf_token. But still, it is strange that the request was redirected instead of getting exception.

jlrdw's avatar

Does your IDE have grep built in, do a search that way to track down the problem.

Please or to participate in this conversation.