|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Illuminate\Database\Eloquent; |
| 4 | + |
| 5 | +/** |
| 6 | + * @template TModelClass of Model |
| 7 | + * @source https://github.com/netpok/larastan/blob/master/stubs/EloquentBuilder.stub |
| 8 | + * @license MIT |
| 9 | + * @copyright Nuno Maduro [email protected] |
| 10 | + */ |
| 11 | +class Builder |
| 12 | +{ |
| 13 | + /** @phpstan-return TModelClass */ |
| 14 | + public function getModel(); |
| 15 | + |
| 16 | + /** |
| 17 | + * @phpstan-param array<model-property<TModelClass>, mixed> $attributes |
| 18 | + * @phpstan-return TModelClass |
| 19 | + */ |
| 20 | + public function create(array $attributes = []); |
| 21 | + |
| 22 | + /** |
| 23 | + * Create a collection of models from plain arrays. |
| 24 | + * |
| 25 | + * @param array<mixed> $items |
| 26 | + * @phpstan-return \Illuminate\Database\Eloquent\Collection<TModelClass> |
| 27 | + */ |
| 28 | + public function hydrate(array $items); |
| 29 | + |
| 30 | + /** |
| 31 | + * Create a collection of models from a raw query. |
| 32 | + * |
| 33 | + * @param string $query |
| 34 | + * @param array<mixed> $bindings |
| 35 | + * @phpstan-return \Illuminate\Database\Eloquent\Collection<TModelClass> |
| 36 | + */ |
| 37 | + public function fromQuery($query, $bindings = []); |
| 38 | + |
| 39 | + /** |
| 40 | + * Find a model by its primary key. |
| 41 | + * |
| 42 | + * @param mixed $id |
| 43 | + * @param array<int, (model-property<TModelClass>|'*')>|model-property<TModelClass>|'*' $columns |
| 44 | + * @phpstan-return TModelClass|\Illuminate\Database\Eloquent\Collection<TModelClass>|null |
| 45 | + */ |
| 46 | + public function find($id, $columns = ['*']); |
| 47 | + |
| 48 | + /** |
| 49 | + * Find multiple models by their primary keys. |
| 50 | + * |
| 51 | + * @param \Illuminate\Contracts\Support\Arrayable|array<mixed> $ids |
| 52 | + * @param array<int, (model-property<TModelClass>|'*')>|model-property<TModelClass>|'*' $columns |
| 53 | + * @phpstan-return \Illuminate\Database\Eloquent\Collection<TModelClass> |
| 54 | + */ |
| 55 | + public function findMany($ids, $columns = ['*']); |
| 56 | + |
| 57 | + /** |
| 58 | + * Find a model by its primary key or throw an exception. |
| 59 | + * |
| 60 | + * @param mixed $id |
| 61 | + * @param array<int, (model-property<TModelClass>|'*')>|model-property<TModelClass>|'*' $columns |
| 62 | + * @phpstan-return TModelClass|\Illuminate\Database\Eloquent\Collection<TModelClass> |
| 63 | + * |
| 64 | + * @throws \Illuminate\Database\Eloquent\ModelNotFoundException |
| 65 | + */ |
| 66 | + public function findOrFail($id, $columns = ['*']); |
| 67 | + |
| 68 | + /** |
| 69 | + * Find a model by its primary key or return fresh model instance. |
| 70 | + * |
| 71 | + * @param mixed $id |
| 72 | + * @param array<int, (model-property<TModelClass>|'*')>|model-property<TModelClass>|'*' $columns |
| 73 | + * @phpstan-return TModelClass |
| 74 | + */ |
| 75 | + public function findOrNew($id, $columns = ['*']); |
| 76 | + |
| 77 | + /** |
| 78 | + * Get the first record matching the attributes or instantiate it. |
| 79 | + * |
| 80 | + * @param array<model-property<TModelClass>, mixed> $attributes |
| 81 | + * @param array<model-property<TModelClass>, mixed> $values |
| 82 | + * @phpstan-return TModelClass |
| 83 | + */ |
| 84 | + public function firstOrNew(array $attributes = [], array $values = []); |
| 85 | + |
| 86 | + /** |
| 87 | + * Get the first record matching the attributes or create it. |
| 88 | + * |
| 89 | + * @param array<model-property<TModelClass>, mixed> $attributes |
| 90 | + * @param array<model-property<TModelClass>, mixed> $values |
| 91 | + * @phpstan-return TModelClass |
| 92 | + */ |
| 93 | + public function firstOrCreate(array $attributes, array $values = []); |
| 94 | + |
| 95 | + /** |
| 96 | + * Create or update a record matching the attributes, and fill it with values. |
| 97 | + * |
| 98 | + * @param array<model-property<TModelClass>, mixed> $attributes |
| 99 | + * @param array<model-property<TModelClass>, mixed> $values |
| 100 | + * @phpstan-return TModelClass |
| 101 | + */ |
| 102 | + public function updateOrCreate(array $attributes, array $values = []); |
| 103 | + |
| 104 | + /** |
| 105 | + * @param array<model-property<TModelClass>, mixed> $attributes |
| 106 | + * @return \Illuminate\Database\Eloquent\Model|$this |
| 107 | + */ |
| 108 | + public function forceCreate(array $attributes); |
| 109 | + |
| 110 | + /** |
| 111 | + * @param array<model-property<TModelClass>, mixed> $values |
| 112 | + * @return int |
| 113 | + */ |
| 114 | + public function update(array $values); |
| 115 | + |
| 116 | + /** |
| 117 | + * Execute the query and get the first result or throw an exception. |
| 118 | + * |
| 119 | + * @param array<int, (model-property<TModelClass>|'*')>|model-property<TModelClass>|'*' $columns |
| 120 | + * @phpstan-return TModelClass |
| 121 | + * |
| 122 | + * @throws \Illuminate\Database\Eloquent\ModelNotFoundException |
| 123 | + */ |
| 124 | + public function firstOrFail($columns = ['*']); |
| 125 | + |
| 126 | + /** |
| 127 | + * Execute the query and get the first result or call a callback. |
| 128 | + * |
| 129 | + * @param \Closure|array<int, (model-property<TModelClass>|'*')> $columns |
| 130 | + * @param \Closure|null $callback |
| 131 | + * @phpstan-return TModelClass|mixed |
| 132 | + */ |
| 133 | + public function firstOr($columns = ['*'], \Closure $callback = null); |
| 134 | + |
| 135 | + /** |
| 136 | + * Add a basic where clause to the query. |
| 137 | + * |
| 138 | + * @param \Closure|model-property<TModelClass>|array<model-property<TModelClass>|int, mixed>|\Illuminate\Database\Query\Expression $column |
| 139 | + * @param mixed $operator |
| 140 | + * @param mixed $value |
| 141 | + * @param string $boolean |
| 142 | + * @return $this |
| 143 | + */ |
| 144 | + public function where($column, $operator = null, $value = null, $boolean = 'and'); |
| 145 | + |
| 146 | + /** |
| 147 | + * Add an "or where" clause to the query. |
| 148 | + * |
| 149 | + * @param \Closure|model-property<TModelClass>|array<model-property<TModelClass>|int, mixed>|\Illuminate\Database\Query\Expression $column |
| 150 | + * @param mixed $operator |
| 151 | + * @param mixed $value |
| 152 | + * @return $this |
| 153 | + */ |
| 154 | + public function orWhere($column, $operator = null, $value = null); |
| 155 | + |
| 156 | + /** |
| 157 | + * Add a basic where clause to the query, and return the first result. |
| 158 | + * |
| 159 | + * @param \Closure|model-property<TModelClass>|array<model-property<TModelClass>|int, mixed>|\Illuminate\Database\Query\Expression $column |
| 160 | + * @param mixed $operator |
| 161 | + * @param mixed $value |
| 162 | + * @param string $boolean |
| 163 | + * @phpstan-return TModelClass|null |
| 164 | + */ |
| 165 | + public function firstWhere($column, $operator = null, $value = null, $boolean = 'and'); |
| 166 | + |
| 167 | + /** |
| 168 | + * Execute the query as a "select" statement. |
| 169 | + * |
| 170 | + * @param array<int, (model-property<TModelClass>|'*')>|model-property<TModelClass>|'*' $columns |
| 171 | + * @phpstan-return \Illuminate\Database\Eloquent\Collection<TModelClass> |
| 172 | + */ |
| 173 | + public function get($columns = ['*']); |
| 174 | + |
| 175 | + /** |
| 176 | + * Get the hydrated models without eager loading. |
| 177 | + * |
| 178 | + * @param array<int, (model-property<TModelClass>|'*')>|model-property<TModelClass>|'*' $columns |
| 179 | + * @phpstan-return TModelClass[] |
| 180 | + */ |
| 181 | + public function getModels($columns = ['*']); |
| 182 | + |
| 183 | + /** |
| 184 | + * Get a single column's value from the first result of a query. |
| 185 | + * |
| 186 | + * @param model-property<TModelClass>|\Illuminate\Database\Query\Expression $column |
| 187 | + * @return mixed |
| 188 | + */ |
| 189 | + public function value($column); |
| 190 | + |
| 191 | + /** |
| 192 | + * Apply the callback's query changes if the given "value" is true. |
| 193 | + * |
| 194 | + * @param mixed $value |
| 195 | + * @param callable($this, mixed): null|Builder<TModelClass> $callback |
| 196 | + * @param callable($this, mixed): null|Builder<TModelClass>|null $default |
| 197 | + * @return mixed|$this |
| 198 | + */ |
| 199 | + public function when($value, $callback, $default = null); |
| 200 | + |
| 201 | + /** |
| 202 | + * Apply the callback's query changes if the given "value" is false. |
| 203 | + * |
| 204 | + * @param mixed $value |
| 205 | + * @param callable($this, mixed): null|Builder<TModelClass> $callback |
| 206 | + * @param callable($this, mixed): null|Builder<TModelClass>|null $default |
| 207 | + * @return mixed|$this |
| 208 | + */ |
| 209 | + public function unless($value, $callback, $default = null); |
| 210 | +} |
0 commit comments