Comments (14)
A fix for this was to do the following for my model:
Change:
class Model extends \Eloquent {
To:
use \Illuminate\Database\Eloquent\Model as Eloquent;
class Model extends Eloquent {
Kind of stinks to do that, but it works and removes the errors in PhpStorm...
from laravel-ide-helper.
Hmm yes I understand.
The problem is that Laravel uses facades to use the static syntax on non-static functions, but it isn't always consistent. I guess it should work when I just extend the \Illuminate\Database\Eloquent\Model instead of the QueryBuilder, but then some other functions will be missing, so I don't really see an optimal way to handle this.
So I'm open to ideas ;)
from laravel-ide-helper.
I think having something in the module's README pointing out this "issue" with my fix with use the use
syntax on the model would be the best way.
Kind of a hassle, but I guess that's the side effect of using static methods in the core. haha
from laravel-ide-helper.
Using \Illuminate\Database\Eloquent\Model instead of Eloquent has the downside that you lose the autocomplete on the models. I added an option in the config to skip certain classes, that are in the facade root, but shouldn't be static.
freshTimestamp is added by default, but if there are other classes that don't belong there, please let me know!
from laravel-ide-helper.
Ah, now that I think of it, instead of skipping, it is probably better to make them non-static. But should still fix your issue ;)
from laravel-ide-helper.
So this is interesting. Here is an example _ide_helper_models.php of mine: http://paste.laravel.com/r23
I have this in one of my controllers:
/** @var \v1\Metadata\Artist $artist */
$artist = \v1\Metadata\Artist::find(1);
if ($artist->source == 1) return;
Using PhpStorm, the "source" auto complete does not work. The message I get when hovering that pointer is:
Field accessed via magic method
I'm going to tweak the _ide_helper_models.php class manually as I have a hunch as to why this is happening, but I'm not 100% certain.
from laravel-ide-helper.
As I thought, if you format the _ide_helper_models.php like this methods AND properties work correctly with PhpStorm:
<?php
namespace v1\Metadata;
/**
*
* Generated properties for v1\Metadata\Artist
*
* @property integer $id
* @property string $source_id
* @property string $source
* @property string $name
* @property string $view_url
* @property integer $created_at
* @property integer $updated_at
* @property-read \Illuminate\Database\Eloquent\Collection|v1\Metadata\Artist\Attribute[] $attributes
* @property-read \Illuminate\Database\Eloquent\Collection|v1\Metadata\Album[] $albums
* @property-read \Illuminate\Database\Eloquent\Collection|v1\Metadata\Song[] $songs
* @property-read v1\Metadata\Artist\Biography $biography
*
*/
class Artist {}
I got this idea from looking at the bootstrap\compiled.php
file as that's how Taylor formats that file.
from laravel-ide-helper.
Hmm, I didn't use namespaces with the models indeed.
But are you using the ide_helpers_models.php file as it is generated? I would suggest you copy the generated properties and place them in the real Model, and then just delete the file.
If you have both that file and the model declarations, phpStorm doesn't know which one to choose.
And do you need that inline @var doc? With the latest changes, find() should return static, which phpStorm would interpret as the calling class.
from laravel-ide-helper.
I'm moving docs over now. I've had issues with find()'s @return doc and PhpStorm in the past; but let's see if the latest EAP works this way. I'll report back shortly.
from laravel-ide-helper.
Feature request though, is there a way you can add in a way to generate PHPDoc for a specific model? That way I don't have to run the command then hunt down the model I need? As our app grows we'll have around 70-90 models...
And one more thing, on the generated @property-read
you need to prefix the classes with a backslash. For example:
@property-read v1\Metadata\Album $album
Needs to be:
@property-read \v1\Metadata\Album $album
As when in the Artist model, we are in the v1\Metadata
namespace so your current methodology is looking for v1\Metadata\v1\Metadata\Album
.
from laravel-ide-helper.
You can do php artisan ide-helper:models MyModel
but I'm not sure if that works with namespaces.
from laravel-ide-helper.
Should work now, but you do have to use \ instead of
php artisan ide-helper:models v1\\Metadata\\Album
And the helper files should have correct namespaces also.
from laravel-ide-helper.
Awesome, namespace model generation now works. Thanks!
Looks like that we have the following outstanding:
- Change
@property-read v1\Metadata\Album $album
to be@property-read \v1\Metadata\Album $album
Additional notes:
::find()
returns\Illuminate\Database\Eloquent\Model
so the@var
declaration is indeed needed :(
Thanks a lot for the quick response and support! This utility has saved me a lot of time generating PHPDoc for my autocompletion needs. It's almost perfect! :)
from laravel-ide-helper.
Okay, that first one should be fixed now I think.
The second, that is weird. Do you still use use \Illuminate\Database\Eloquent\Model as Eloquent;
?
If so, remove that line, it shouldn't be needed. And if you use it, you don't use the find() method from my IDE helper.
If that is not the issue, what does the the find() in Eloquent in _ide_helper.php return? Mine has @return static.
from laravel-ide-helper.
Related Issues (20)
- It just doesn't suggest methods from Illuminate\Database\Eloquent\Builder on my model, like "first()" or "where()" HOT 4
- Installation error on latest laravel installation HOT 3
- Is it Possible to Add auto-complete in form request classes?
- Models that have `static::$snakeAttributes` set to `true` should use attribute names without case conversion
- Allow configuration of the expectedMixins when calling Eloquent::writeEloquentModelHelper()
- Model's --write duplicates array properties that have summary and array key-value types added HOT 3
- Modifications required to support Laravel 11 HOT 1
- [idea] Refactor to use phpstan/phpdoc-parser HOT 2
- [2.15.0] Inserting AllowDynamicProperties attribute breaks final classes HOT 4
- Nova Resources HOT 8
- Mixin Information Provided by Packages HOT 2
- Attribute accessor/mutator without the counterparts generate wrong model properties HOT 1
- Support for Eloquent Scope extensions HOT 1
- Not working with MSSQL 2016 and below HOT 2
- Wrong return type get() method HOT 1
- @mixin Alternative HOT 1
- I believe I've been able to improve some of the intellisense for model queries, please implement this (but maybe expand it first) HOT 4
- Comment keeps getting appended
- The command "ide-helper:models" is not working correctly. HOT 1
- Exception: No query results for model inside on mutator or accessor HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel-ide-helper.