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

Exception when try to create a Controller without the base abstract Controller #50494

Closed
devajmeireles opened this issue Mar 12, 2024 · 4 comments · Fixed by #50505
Closed

Exception when try to create a Controller without the base abstract Controller #50494

devajmeireles opened this issue Mar 12, 2024 · 4 comments · Fixed by #50505
Labels

Comments

@devajmeireles
Copy link
Contributor

Laravel Version

11.0.3

PHP Version

8.2.16

Database Driver & Version

SQLite

Description

Starting from the Laravel 11 we can delete the base abstract Controller and remove all extends, the application will continue work without any error, but when we do that we have an error when we try to create a new controller by using the Artisan.

CleanShot 2024-03-12 at 20 10 05

The question is: the base abstract Controller is mandatory or not? If the answer to this question is not, then this exception is wrong.

Steps To Reproduce

  1. Prepare a fresh Laravel 11 application
  2. Delete the base abstract Controller
  3. Try to create a new controller by using Artisan
@devajmeireles devajmeireles changed the title Exception when try to create a Controller without the base Controller Exception when try to create a Controller without the base abstract Controller Mar 12, 2024
@crynobone
Copy link
Member

CleanShot 2024-03-13 at 08 27 22

Unable to recreate the issue.

@devajmeireles
Copy link
Contributor Author

I created a fresh Laravel 11 and the same error happened.

CleanShot 2024-03-12 at 22 52 00

I was only able to create a new controller without the base abstract Controller when I ran:

composer dump-autoload

I think this is happening because Laravel 11 uses class_exists to check if the Controller file exists. I will suggest a PR that uses file_exists, because if this file is moved, the base abstract controller will not be used anyway since the code uses a hard-coded reference to this file:

$baseControllerExists = class_exists($rootNamespace.'Http\Controllers\Controller');

@driesvints
Copy link
Member

I was able to reproduce this. We should indeed do the file_exists check.

@devajmeireles
Copy link
Contributor Author

I was able to reproduce this. We should indeed do the file_exists check.

Thanks for the PR. I forgot to do that yesterday! 😅

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

Successfully merging a pull request may close this issue.

3 participants