© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
4 replies
HL

->relationship() with hasOneThrough() relation doesn't work anymore

Hi guys, in my Account model I have this relation:
public function games()
    {
        return $this->hasOneThrough(
            Game::class,
            SmurfType::class,
            'id', // Foreign key on SmurfType table
            'id', // Foreign key on Game table
            'smurftype', // Local key on Account table
            'game' // Local key on SmurfType table
        );
    }
public function games()
    {
        return $this->hasOneThrough(
            Game::class,
            SmurfType::class,
            'id', // Foreign key on SmurfType table
            'id', // Foreign key on Game table
            'smurftype', // Local key on Account table
            'game' // Local key on SmurfType table
        );
    }


In v2 I used this and it worked perfectly:
SelectFilter::make('game')
                    ->relationship('games', 'name'),
SelectFilter::make('game')
                    ->relationship('games', 'name'),


Now it gives me this error:

Filament\Forms\Components\Select::getRelationship(): Return value must be of type Illuminate\Database\Eloquent\Relations\BelongsTo|Illuminate\Database\Eloquent\Relations\BelongsToMany|Znck\Eloquent\Relations\BelongsToThrough|null, Illuminate\Database\Eloquent\Relations\HasOneThrough returned


Is there a way to solve this without manually giving options and a query method myself, like it used to be?
Solution
The only solution for now seems to be to use this package:
https://github.com/staudenmeir/belongs-to-through

And the relationship should look like htis:

use \Znck\Eloquent\Traits\BelongsToThrough;

public function games()
    {
        return $this->belongsToThrough(
            Game::class,
            SmurfType::class,
            null,
            '',
            [Game::class => 'game', SmurfType::class => 'smurftype']
        );
    }
use \Znck\Eloquent\Traits\BelongsToThrough;

public function games()
    {
        return $this->belongsToThrough(
            Game::class,
            SmurfType::class,
            null,
            '',
            [Game::class => 'game', SmurfType::class => 'smurftype']
        );
    }
GitHub
GitHub - staudenmeir/belongs-to-through: Laravel Eloquent BelongsTo...
Laravel Eloquent BelongsToThrough relationships. Contribute to staudenmeir/belongs-to-through development by creating an account on GitHub.
GitHub - staudenmeir/belongs-to-through: Laravel Eloquent BelongsTo...
Jump to solution
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Export action doesn't work anymore
FilamentFFilament / ❓┊help
2y ago
❓ SpatieMediaLibraryFileUpload on repeater with relation doesn't work
FilamentFFilament / ❓┊help
2y ago
Relation manager with intermediate relationship
FilamentFFilament / ❓┊help
3y ago
Locale switcher doesn't work properly on form repeater with relationship
FilamentFFilament / ❓┊help
3y ago