Issues (71)

src/Layouts/LayoutTraits/HasFieldsCollection.php (1 issue)

Labels
Severity
1
<?php
2
3
namespace NovaFlexibleContent\Layouts\LayoutTraits;
4
5
use Laravel\Nova\Fields\FieldCollection;
6
use Laravel\Nova\Http\Requests\NovaRequest;
7
8
trait HasFieldsCollection
9
{
10
    /**
11
     * The layout's registered fields.
12
     */
13
    protected ?FieldCollection $fields = null;
14
15
    /**
16
     * Provided by developer fields.
17
     */
18 2
    protected function fields(): array
19
    {
20 2
        return $this->fields ? $this->fields->all() : [];
21
    }
22
23
    /**
24
     * Retrieve the layout's fields as a collection.
25
     */
26 17
    public function fieldsCollection(): FieldCollection
27
    {
28 17
        $fields = $this->fields;
29 17
        if(!$fields || $fields->isEmpty()) {
30 17
            $fields = $this->fields();
31
        }
32
33 17
        return FieldCollection::make($fields);
0 ignored issues
show
It seems like $fields can also be of type array; however, parameter $items of Illuminate\Support\Collection::make() does only seem to accept Illuminate\Contracts\Support\Arrayable, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

33
        return FieldCollection::make(/** @scrutinizer ignore-type */ $fields);
Loading history...
34
    }
35
36
    /**
37
     * Filter the layout's fields for detail view.
38
     */
39 1
    public function filterForDetail(NovaRequest $request, mixed $resource): static
40
    {
41 1
        $this->fields = $this->fieldsCollection()->filterForDetail($request, $resource);
42
43 1
        return $this;
44
    }
45
}
46