-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Using ide-helper outside the framework with just illuminate/database #756
Comments
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
😱 |
This still helped me in 2022 😄 thanks!! |
Nice! Also: I'm still using it (which also means that part has not migrated to Laravel, which is the sad part) |
@mfn I created a library with your recommendations, for me it is working correctly. Thanks for the contributions. |
I'm creating this issue because maybe it helps others which are interested in a similar solution and maybe there's interest in making the ide-helper code slightly more agnostic.
My scenario:
If you never heard about this, you wouldn't know this really works and you can use Eloquent outside the framework.
But working with models without ide-helper is very annoying (also for static analysis like phpstan) so I was seeking a solution to make it possible to use ide-helper for two things:
I did not evaluate the generation of Facade data as I'm not using them.
To make the
models
command workbase_path()
global helper from the frameworkIn
\Barryvdh\LaravelIdeHelper\Console\ModelsCommand::loadModels
it uses the global helperbase_path()
which isn't available outside of the framework (it's defined in vendor/laravel/framework/src/Illuminate/Foundation/helpers.php)base_path()
which I only load in the context of generating the models which creates me the correct pathConfig
serviceMultiple times the
$this->laravel['config']
service is access to load the configuration. However I'm not usingilluminate/config
either. I've created a one-shot anonymous class with my code which emulates the most basic methods to make this work. I used below code and and bound it to my container via$laravelContainer->instance('config', …)
; in below codeArr::get
can be used because of the dependencies of other packages toilluminate/support
:To make the
meta
command workMetaCommand
constructor; it's looks like a hack but works :::make()
method which I wanted to add to the generated file. I couldn't find a way to change\Barryvdh\LaravelIdeHelper\Console\MetaCommand::$methods
so I created my ownMyMetaCommand extends MetaCommand
class and just override theprotected $methods
propertyFinishing words
I didn't really knew upfront if I could make it work. I'm really happy it did, having known the ide-helper for years form real Laravel project I truly didn't wanted to miss it!
I think the only suggestions I would have:
base_path()
inside\Barryvdh\LaravelIdeHelper\Console\ModelsCommand
, but pass it asstring $basePath
property to the commands constructor via\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider
\Barryvdh\LaravelIdeHelper\Console\MetaCommand::$methods
once the command is created.\Barryvdh\LaravelIdeHelper\Console\ModelsCommand::createPhpDocs
the@mixin \Eloquent
is harcoded. I'm not even using Facades so if I still would would the mixin I would need them to point both the
Eloquent\Builderand
Query\Builder`; I left it as it for nowOtherwise: really very great package and I hope I continues to work also on the standalone versions in the future.
PS: feel free to close the issue, I merely wanted to document it for my future self/others
The text was updated successfully, but these errors were encountered: