Skip to content

Commit dc87f97

Browse files
committed
Add go-to-definition for Eloquent $dates and where{Property} entries
1 parent 410772f commit dc87f97

24 files changed

Lines changed: 542 additions & 87 deletions

docs/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616
### Fixed
1717

1818
- **Type hierarchy registration.** Dynamic registration for type hierarchy is now gated on client capability, preventing errors in editors that don't support it.
19+
- **Eloquent `$dates` and `where{Property}` go-to-definition.** Ctrl+clicking a property backed by the `$dates` array now jumps to the string entry inside `$dates`, matching the behaviour already supported for `$casts`, `$attributes`, `$fillable`, `$guarded`, `$hidden`, `$visible`, and `$appends`. Ctrl+clicking a `where{Property}()` dynamic method (e.g. `whereFlour`, `whereKitchenId`) now jumps to the corresponding column entry in whichever Eloquent array defines that column.
1920
- **Property `self`/`static` type resolution.** Properties declared with `@var self|null` or `static` type annotations now resolve to the owning class name instead of displaying the raw `self`/`static` keyword in hover and type inference.
2021
- **Magic `__get` property access.** Accessing undefined properties on objects with a `__get` method now resolves to the method's declared return type, even when `__get` has no template parameters (e.g. `SimpleXMLElement::$child` resolves to `SimpleXMLElement`).
2122
- **Magic `__call` method return type.** Calling undefined methods on objects with a `__call` method now resolves to `__call`'s declared return type for hover and type inference.

examples/laravel/app/Demo.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ class LaravelConfigDemo
234234
public function demo(): void
235235
{
236236
config('app.name');
237-
\Illuminate\Support\Facades\Config::get('database.default');
238-
\Illuminate\Support\Facades\Config::set('app.timezone', 'UTC');
237+
Config::get('database.default');
238+
Config::set('app.timezone', 'UTC');
239239
}
240240
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace App\Models;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
7+
class AuthorProfile extends Model
8+
{
9+
public function getBio(): string { return ''; }
10+
public function getAvatar(): string { return ''; }
11+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace App\Models;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
7+
class Baker extends Model
8+
{
9+
public function getName(): string { return ''; }
10+
}

examples/laravel/app/Models/Bakery.php

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -77,41 +77,3 @@ protected function sprinkle(): Attribute
7777
return new Attribute();
7878
}
7979
}
80-
81-
class Loaf extends Model
82-
{
83-
public function getWeight(): int { return 0; }
84-
}
85-
86-
class Baker extends Model
87-
{
88-
public function getName(): string { return ''; }
89-
}
90-
91-
class BakeryRecipe extends Model
92-
{
93-
public function getTitle(): string { return ''; }
94-
}
95-
96-
enum JamFlavor: string
97-
{
98-
case Strawberry = 'strawberry';
99-
case Raspberry = 'raspberry';
100-
case Blueberry = 'blueberry';
101-
}
102-
103-
class Frosting
104-
{
105-
public function __construct(private string $flavor = '') {}
106-
public function getFlavor(): string { return $this->flavor; }
107-
public function isSweet(): bool { return $this->flavor !== ''; }
108-
public function __toString(): string { return $this->flavor; }
109-
}
110-
111-
class FrostingCast
112-
{
113-
public function get($model, string $key, mixed $value, array $attributes): ?Frosting
114-
{
115-
return new Frosting((string) $value);
116-
}
117-
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace App\Models;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
7+
class BakeryRecipe extends Model
8+
{
9+
public function getTitle(): string { return ''; }
10+
}

examples/laravel/app/Models/BlogAuthor.php

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,3 @@ public function scopeOfGenre(\Illuminate\Database\Eloquent\Builder $query, strin
3232
$query->where('genre', $genre);
3333
}
3434
}
35-
36-
class BlogPost extends Model
37-
{
38-
public function getTitle(): string { return ''; }
39-
public function getSlug(): string { return ''; }
40-
41-
/** @return \Illuminate\Database\Eloquent\Relations\BelongsTo<BlogAuthor, covariant $this> */
42-
public function author(): mixed { return $this->belongsTo(BlogAuthor::class); }
43-
}
44-
45-
class AuthorProfile extends Model
46-
{
47-
public function getBio(): string { return ''; }
48-
public function getAvatar(): string { return ''; }
49-
}
50-
51-
class BlogTag extends Model
52-
{
53-
public function getLabel(): string { return ''; }
54-
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace App\Models;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
7+
class BlogPost extends Model
8+
{
9+
public function getTitle(): string { return ''; }
10+
public function getSlug(): string { return ''; }
11+
12+
/** @return \Illuminate\Database\Eloquent\Relations\BelongsTo<BlogAuthor, covariant $this> */
13+
public function author(): mixed { return $this->belongsTo(BlogAuthor::class); }
14+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace App\Models;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
7+
class BlogTag extends Model
8+
{
9+
public function getLabel(): string { return ''; }
10+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace App\Models;
4+
5+
class Frosting
6+
{
7+
public function __construct(private string $flavor = '') {}
8+
public function getFlavor(): string { return $this->flavor; }
9+
public function isSweet(): bool { return $this->flavor !== ''; }
10+
public function __toString(): string { return $this->flavor; }
11+
}

0 commit comments

Comments
 (0)