spatie / laravel-ray

Debug with Ray to fix problems faster in Laravel apps
https://myray.app
MIT License
291 stars 64 forks source link

Try catch `DB::enableQueryLog` to Handle Cases when connection is not setup. #219

Closed bogdankharchenko closed 2 years ago

bogdankharchenko commented 3 years ago

Problem: Vapor injects DB* -- when deploying to Vapor, DB* is not set from .env pull thus this fails during composer autoload.

freekmurze commented 3 years ago

The tests are failing for this one, could you take a look at that?

bogdankharchenko commented 3 years ago

The tests are failing for this one, could you take a look at that?

Looking at it today -- didn't have time yesterday!

bogdankharchenko commented 3 years ago

@freekmurze so I took another stab at it

and the real issue is that -- the db connection is just not properly setup during composer install.

Steps to reproduce:
Install Fresh Laravel + Laravel-Ray without having a "forge" database as specified. And this will fail during composer autoload.

So I figured, perhaps we just check if we even have a connection in the first place, rather than looking at the config. Seems to be a solution, but I'll be interested to know a better approach from your angle.

Thanks!

freekmurze commented 3 years ago

This PR is marked as draft. et me know when it is ready to be reviewed.

bogdankharchenko commented 3 years ago

@freekmurze I removed the draft -- go ahead and take a look

Nielsvanpach commented 3 years ago

Hi @bogdankharchenko, how can I reproduce this issue? I'm not having any issues running composer dump-autoload with an invalid database name in the .env file. And can you share your exception?

bogdankharchenko commented 3 years ago

@Nielsvanpach hey just do, fresh install and set

DB_CONNECTION=invalid_connection

https://docs.vapor.build/1.0/projects/environments.html#environment-variables