forked from larastan/larastan
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmodel-builder.php
More file actions
60 lines (47 loc) · 1.7 KB
/
model-builder.php
File metadata and controls
60 lines (47 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
namespace ModelBuilder;
use App\Post;
use App\PostBuilder;
use App\Team;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
use function PHPStan\Testing\assertType;
class User extends Model
{
/** @return Builder<static> */
public static function testQueryStatic(): Builder
{
return static::query();
}
public static function testCreateStatic(): static
{
return static::query()->create();
}
public static function testCreateSelf(): static
{
return self::query()->create();
}
}
function test(): void
{
\App\User::query()->where(DB::raw('1'), 1)->get();
/** @see https://github.com/larastan/larastan/issues/1806 */
\App\User::query()->orderBy(Post::query()->select('id')->whereColumn('user_id', 'users.id'));
\App\User::query()->orderByDesc(Post::query()->select('id')->whereColumn('user_id', 'users.id'));
\App\User::query()->get()->pluck('computed');
/** @see https://github.com/larastan/larastan/issues/1952 */
Team::query()->where('name', 'Team A')->orderBy('name')->get();
\App\User::query()->whereHas('posts', function ($query) {
assertType('App\PostBuilder<App\Post>', $query);
return $query->where('name', 'like', 'Foo%');
})->get();
\App\User::query()->whereHas('posts', function (Builder $query) {
assertType('App\PostBuilder<App\Post>', $query);
return $query->where('name', 'like', 'Foo%');
})->get();
\App\User::query()->whereHas('posts', function (PostBuilder $query) {
assertType('App\PostBuilder<App\Post>', $query);
return $query->where('name', 'like', 'Foo%');
})->get();
}