Roboroads / laravel-tinker

Adds a way to write php and run it directly in Laravels' Artisan Tinker.
Apache License 2.0
211 stars 15 forks source link

[Bug]: Laravel detection fails when Laravel is included by another composer dependency #364

Open caimaxtingle opened 2 months ago

caimaxtingle commented 2 months ago

Short bug description

When including Laravel via another composer dependency it's not booted in tinker

Extended bug description

Since the addition of Laravel detection composer set-ups where another composer.json dependency includes laravel/framework no longer work with the tinker plugin, as $isLaravelProject (of tinker_run.php) is false and thus the kernel isn't required/bootstrapped

Your project is not the problem

How to reproduce?

  1. Create a repo which includes a composer.json that requires laravel/framework
  2. Create another repo which includes the first repo in its composer.json
  3. Attempt to use a Laravel function in tinker, eg: echo app()->environment() . PHP_EOL;

Expected behavior

Laravel would be booted and the code execute under tinker

Screenshots

No response

IDE & Version

PHPStorm 2024.1.4

PHP Version

8.3

OS and version

Windows 11

Laravel Tinker plugin version

2.7.3

Interpreter type

Remote

Laravel Version

v11.18.0

Tinker version

v2.9.0

Psysh version

v0.12.4

Additional Context

Simply checking the composer.lock instead of the composer.json to see if Laravel exists will resolve this problem

Roboroads commented 1 month ago

Hmmmmmmmmmmmmm, yea I could see that being a problem. Should detect if the file vendor/laravel/framework/conposer.json exists maybe instead. Or indeed, check the lockfile (if that's an easier option, idk..)