Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling Artisan::call('route:list') produces an error #50782

Closed
espenkn opened this issue Mar 27, 2024 · 4 comments
Closed

Calling Artisan::call('route:list') produces an error #50782

espenkn opened this issue Mar 27, 2024 · 4 comments

Comments

@espenkn
Copy link

espenkn commented Mar 27, 2024

Laravel Version

11.1.0

PHP Version

8.2.17

Database Driver & Version

No response

Description

When i run Artisan::call('route:list')

from a controller I get an error saying Target class [web] does not exist. but if i capture the output with a BufferedOutput the contents of output is the expected value.

Looks like the command is trying resolve the 'web' middleware and that results in a BindingResolutionException.

Is this a bug or a usage error from my side?

Steps To Reproduce

class AdminController extends Controller
{
    function ApiTester()
    {
        Artisan::call('route:list');
        // This view will print the exception
        return view('admin.apitester');
    }
}
@joy2362
Copy link

joy2362 commented Mar 27, 2024

@esbenp are you trying this in the web route or API route?

@espenkn
Copy link
Author

espenkn commented Mar 27, 2024

This is in the web route but with sanctum like this (abbreviated)

Route::middleware('auth:sanctum')->group(function() {
    Route::prefix('admin')->controller(AdminController::class)->group(function() {
        Route::get('/apitester', 'ApiTester');
    });

@driesvints
Copy link
Member

I'm not sure it makes sense to call this command in that way.

@espenkn
Copy link
Author

espenkn commented Mar 28, 2024

I'm not sure it makes sense to call this command in that way.

So i have a web page where i can experiment with the API that works and is a great timesaver, but I thought It would be nice to list out the defined API routes in the browser so I dont have to look that up. So for my app this makes perfect sense. I do capture the output and presetnt that in my api tester page and everything works, but this also generates the exception as a side effect. I PRESENTED THE MINIMAL EXAMPLES TO REPORDUCE the issue, not what I do exactly in my app.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants