-
-
Notifications
You must be signed in to change notification settings - Fork 91
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
Undefined method when scope is an interface but implementation class is expected or configured #1051
Comments
This line below is probably setting the type of $user = auth()->user(); When you hover on |
I have got the same error. Help Please! |
I also have the same problem
|
Yes, this is the source of many issues in my projects as well. Because if you use
That really clutters the code tho, that's a downside. I wish intelephense would automatically know it's an instance of a user model. @bmewburn - is that enough information? |
Laravel's docblock for <?php
namespace Illuminate\Contracts\Auth;
interface Guard
{
/**
* Determine if the current user is authenticated.
*
* @return bool
*/
public function check();
/**
* Determine if the current user is a guest.
*
* @return bool
*/
public function guest();
/**
* Get the currently authenticated user.
*
* @return \Illuminate\Contracts\Auth\Authenticatable|null
*/
public function user(); .... the Technically intelphense doesn't know that so it says that methods don't exist when in fact they most likely do. So you have to type hint to intelephense what's returned is a version of your user model: <?php
/** @var \App\User|null $user */
$user = $this->auth->user(); As someone else mentioned, this does clutter your code a fair bit. I'm not sure what the alternative would be though, Laravel does this pretty much everywhere - it returns a "Contract" interface in the docblock. Another issue with Laravel support for intelephense is with facades. It often complains: <?php
Route::get('some-url');
?> This will be marked as not knowing what |
@garygreen is correct. Intelephense is working as expected here. Using |
Illuminate\Support\Facades\Auth::user
|
In 1.5 intelephense will prefer definitions not found in vendor. This enables you to override vendor definitions by providing a helper stub somewhere in the workspace. It also means that _ide_helper.php will be preferred. For the specific case of |
You're right @NEGits . Fixed in 1.5.3 |
this still seems to be an issue (I have the same problem as described above, running 1.5.4)...is there another Issue tracking this or shit it be reopened? |
+1 |
+1 ... Those underlines makes me feel uncomfortable |
Still not fixed. |
+1 |
If you are using ide-helper then calling <?php
namespace Illuminate\Contracts\Auth {
interface Guard
{
/**
* Get the currently authenticated user.
*
* @return \App\User|null
*/
public function user();
}
} |
As I noted in my comment above, I'm using ide-helper and calling I haven't had time to dig into the underlying cause in intelephense, but just wanted to say that this is still an existing bug. |
@earnjam please open a new ticket with a minimal reproducible example. I'm not seeing this in my laravel tests. |
Thanks, I'll gather as much info as I can and put it into a new ticket. |
@bmewburn Just as a quick update, I created a fresh Laravel project to try to minimally replicate the issue and it worked fine. But my existing projects all had this problem. So I dug into the VS workspace configuration and figured out that it was happening because of the way the folders were configured. I had them configured like this: "folders": [
{
"path": "."
}
] I typically have project directory setups that look something like this:
I'd usually add the whole project directory to the workspace so that I could quickly change workspace config, dev environment config, etc. If I change the workspace configuration and explicitly include the laravel application folder instead of Not sure why that is exactly, but I'll see if I can reconfigure my workspace setups to account for this and maybe this will help others who are encountering the same problem. |
Not sure why this is closed...none of the above helps...still an issue |
my solution was moving to php storm 🫢 |
I have the same issue whilst using Spatie permissions. |
try this and modified it to
|
Sorry for the incredible delay in response, but this works great. Thanks for pointing out the other issue too! |
Describe the bug
There is missing autocompletion when a trait is applied to the class.
To Reproduce
First I've been added Laravel/Passport package. Then added
use HasApiTokens
trait to User model. Then I tried to callcreateToken
method andUndefined method 'createToken'.intelephense(1013)
occurs.Expected behavior
createToken method should appear in the list of autocompletion.
Screenshots
Platform and version
Windows 10, WSL(Ubuntu-18.04), Intelephense 1.3.11
The text was updated successfully, but these errors were encountered: