You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
VsCode with intelephense not detect definition for a function class
Steps To Reproduce:
I have this code:
//app/http/controllers/Api/ProcessController.php
namespace App\Http\Controllers\Api;
use App\Models\Center\Center;
$center = Center::where("uid", 1)->first();
$mySome = $center->getSome(); //No definition found for 'getSome()'
//app/models/Center/Center.php
namespace App\Models\Center;
class Center extends Model {
public function getSome()
{
return "some";
}
}
Then cmd+click or Go to definition "getSome()" on Center class throw: "Not definition found for ...."
The text was updated successfully, but these errors were encountered:
I've tested this on Vscode, intelephense & Laravel 10.41.0. Although my version is slightly higher than yours I don't think it is relevant.
Although it is not provided in your code snippet, I'm assuming that you have generated docblocks for the App\Models\Center. Either way I tested this with generated docblocks and without.
With generated docblocks on App\Models\Center I'm getting that $center is either
\Illuminate\Database\Eloquent\Model|object|static|null
/** Fetched from Illuminate\Database\Concerns\BuildsQueries::first */
So it makes sense that 'go to type definition' doesn't work since intelliphense doesn't know that the variable is actually an instance of App\Models\Center
Without generated docblocks intelephense is reporting that $centeris mixed which again makes sense you are not getting a type definition.
Alternative approaches to get help out intelephense giving intellisense
Use ->get() in combination of first().
$center = $center = Center::where("uid", 1)->get()->first();
$center->getSome(); // Gives you correct go to type definition
Use instanceof to verify that the $center is actually App\Models\Center
$center = Center::where("uid", 1)->first();
if ($center instanceof \App\Models\Center) {
$mySome = $center->getSome(); // Gives you correct go to type definition
}
TLDR; I don't think this a bug with laravel-ide-helper
Versions:
Description:
VsCode with intelephense not detect definition for a function class
Steps To Reproduce:
I have this code:
Then cmd+click or Go to definition "getSome()" on Center class throw: "Not definition found for ...."
The text was updated successfully, but these errors were encountered: