Skip to content

Commit 697ff95

Browse files
committed
Fix model options
1 parent 7dcf8e2 commit 697ff95

File tree

4 files changed

+10
-15
lines changed

4 files changed

+10
-15
lines changed

src/Html/Editor/Fields/BelongsTo.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ public static function model(Builder|string $class, string $text, string $id = '
1919
if ($class instanceof Builder) {
2020
$table = $class->getModel()->getTable();
2121
} else {
22-
$class = new $class;
23-
$table = $class->getTable();
22+
$table = (new $class)->getTable();
2423
}
2524

2625
$table = Str::singular($table);

src/Html/Editor/Fields/Field.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,12 @@ public function type(string $type): static
109109
/**
110110
* Get options from a model.
111111
*
112-
* @param \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Builder $model
112+
* @param class-string|\Illuminate\Database\Eloquent\Builder $model
113113
* @param string $value
114114
* @param string $key
115115
* @return $this
116116
*/
117-
public function modelOptions(Model|EloquentBuilder $model, string $value, string $key = 'id'): static
117+
public function modelOptions($model, string $value, string $key = 'id'): static
118118
{
119119
return $this->options(
120120
Options::model($model, $value, $key)
@@ -331,16 +331,13 @@ public function opts(array $value): static
331331
* Set field element html attributes.
332332
*
333333
* @param string $attribute
334-
* @param int|string $value
334+
* @param int|bool|string $value
335335
* @return $this
336336
* @see https://datatables.net/forums/discussion/comment/156581/#Comment_156581
337337
*/
338-
public function attr(string $attribute, int|string $value): static
338+
public function attr(string $attribute, int|bool|string $value): static
339339
{
340-
if (! is_array($this->attributes['attr'])) {
341-
$this->attributes['attr'] = [];
342-
}
343-
340+
// @phpstan-ignore-next-line
344341
$this->attributes['attr'][$attribute] = $value;
345342

346343
return $this;

src/Html/Editor/Fields/Options.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ public static function yesNo(): static
3333
/**
3434
* Get options from a model.
3535
*
36-
* @param \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Builder $model
36+
* @param class-string|\Illuminate\Database\Eloquent\Builder $model
3737
* @param string $value
3838
* @param string $key
3939
* @return Collection
4040
*/
41-
public static function model(Model|EloquentBuilder $model, string $value, string $key = 'id'): Collection
41+
public static function model(string|EloquentBuilder $model, string $value, string $key = 'id'): Collection
4242
{
4343
if (! $model instanceof EloquentBuilder) {
4444
$model = $model::query();

src/Html/SearchPane.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use Closure;
66
use Illuminate\Contracts\Support\Arrayable;
77
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
8-
use Illuminate\Database\Eloquent\Model;
98
use Illuminate\Support\Fluent;
109
use Yajra\DataTables\Html\Editor\Fields\Options;
1110

@@ -212,12 +211,12 @@ public function hideTotal(bool $value = true): static
212211
/**
213212
* Get options from a model.
214213
*
215-
* @param \Illuminate\Database\Eloquent\Model|EloquentBuilder $model
214+
* @param class-string|EloquentBuilder $model
216215
* @param string $value
217216
* @param string $key
218217
* @return $this
219218
*/
220-
public function modelOptions(Model|EloquentBuilder $model, string $value, string $key = 'id'): static
219+
public function modelOptions(EloquentBuilder|string $model, string $value, string $key = 'id'): SearchPane
221220
{
222221
return $this->options(
223222
Options::model($model, $value, $key)

0 commit comments

Comments
 (0)