laravel / tinker

Powerful REPL for the Laravel framework.
https://laravel.com/docs/artisan#tinker
MIT License
7.32k stars 130 forks source link

Fix command resolving #144

Closed driesvints closed 2 years ago

driesvints commented 2 years ago

This PR fixes an issue where a change in Laravel 9 broke command resolving. The culprit is https://github.com/laravel/framework/pull/34873 which adds support for lazy loading. The change causes a null value to be returned for commands which are suppose to be lazy loaded and therefor these commands were never resolved or added to the Tinker session.

The fix I'm attempting is to use the Laravel container instance instead of the console application. What we want to achieve is to resolve all commands beforehand and add them to the Psysh shell session. Afaik Psysh has no way of handling lazy loaded commands. Therefor we need to resolve them all beforehand.

All commands started working again when I did this change. I do not know of any side effects from making this change.

Fixes https://github.com/laravel/tinker/issues/143

michaelhume commented 2 years ago

When attempting to implement the fix locally, the issue of loading commands from config/tinker.php seems to persist. It appears getLaravel()->resolve() is private

Call to protected method Illuminate\Foundation\Application::resolve() from scope Laravel\Tinker\Console\TinkerCommand
driesvints commented 2 years ago

Fixed, thanks

michaelhume commented 2 years ago

Fixed, thanks

@driesvints can you share the new fix?

driesvints commented 2 years ago

Last commit on the repos main branch

Brenneisen commented 2 years ago

Hi @driesvints, I get the following error when running custom commands with laravel/tinker 2.7.1 and laravel/framework 9.5.1. With 2.7.0 it still works. Seems to be related to this fix.

PHP Error: Call to a member function make() on null in /home/vagrant/workspace/Falcon/backend/vendor/laravel/framework/src/Illuminate/Console/Command.php on line 116