filamentphp / filament

A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS.
https://filamentphp.com
MIT License
18.07k stars 2.83k forks source link

Type error when using Forms\Components\Select::make()->relationship() #7388

Closed dalehurley closed 1 year ago

dalehurley commented 1 year ago

Package

filament/filament

Package Version

v3

Laravel Version

V10.17.0

Livewire Version

v3

PHP Version

PHP 8.2.8

Problem description

When using type hinted relationship like in the example Panel Builder Getting started you get an error:

TypeError
App\Models\Patient::owner(): Return value must be of type App\Models\BelongsTo, Illuminate\Database\Eloquent\Relations\BelongsTo returned
 public function owner(): BelongsTo
    {
        return $this->belongsTo(Owner::class);
    }
           Forms\Components\Select::make('owner_id')
                ->relationship('owner', 'name')
                ->required(),

Expected behavior

The correct BelongTo type detected

Steps to reproduce

Follow the example on https://filamentphp.com/docs/3.x/panels/getting-started

Reproduction repository

https://github.com/DaleMHurley/filament-error

Relevant log output

TypeError
PHP 8.2.8
10.17.0
App\Models\Patient::owner(): Return value must be of type App\Models\BelongsTo, Illuminate\Database\Eloquent\Relations\BelongsTo returned
sumardi commented 1 year ago

Missing

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

It's in the docs.

dalehurley commented 1 year ago

Ok. Feel free to ignore the issue but this is an error you get following the first getting started page. I am just thought that it is worth highlighting as it is likely to turn people off if they follow along and get an error within the first use.

danharrin commented 1 year ago

Can you PR a fix to the docs then?

lordjack commented 1 year ago

Missing

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

It's in the docs.

Thank you for this tip! I had the same error...