© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•2y ago•
4 replies
Lucky0

ManyToMany Relationship on AttachAction

I am trying to use AttachAction, and I am trying to implement it. But instead i got an error

error:
Call to undefined method App\Models\Car\Feature::carOwners()
Call to undefined method App\Models\Car\Feature::carOwners()


model:

namespace App\Models\Car;

class Feature extends Model
{
    public function carFeatures(): BelongsToMany
    {
        return $this->belongsToMany(CarOwner::class, 'car_features')
            ->withPivot(['is_active', 'remark'])
            ->withTimestamps();
    }
}
namespace App\Models\Car;

class Feature extends Model
{
    public function carFeatures(): BelongsToMany
    {
        return $this->belongsToMany(CarOwner::class, 'car_features')
            ->withPivot(['is_active', 'remark'])
            ->withTimestamps();
    }
}


namespace App\Models;

class CarFeature extends Model
{
    public function feature(): BelongsTo
    {
        return $this->belongsTo(CarSpec\Feature::class);
    }

    public function carOwner(): BelongsTo
    {
        return $this->belongsTo(CarOwner::class);
    }
}
namespace App\Models;

class CarFeature extends Model
{
    public function feature(): BelongsTo
    {
        return $this->belongsTo(CarSpec\Feature::class);
    }

    public function carOwner(): BelongsTo
    {
        return $this->belongsTo(CarOwner::class);
    }
}


namespace App\Models;

class CarOwner extends Model
{
    public function carFeatures(): BelongsToMany
    {
        return $this->belongsToMany(CarSpec\Feature::class, 'car_features')
            ->withPivot(['is_active', 'remark'])
            ->withTimestamps();
    }
}
namespace App\Models;

class CarOwner extends Model
{
    public function carFeatures(): BelongsToMany
    {
        return $this->belongsToMany(CarSpec\Feature::class, 'car_features')
            ->withPivot(['is_active', 'remark'])
            ->withTimestamps();
    }
}


namespace App\Filament\Driver\Resources\CarOwnerResource\RelationManagers;

class CarFeaturesRelationManager extends RelationManager
{
    protected static string $relationship = 'carFeatures';

    public function table(Table $table): Table
    {
        return $table
            ->recordTitleAttribute('name')
            ->columns([
                        ...
                    }),
            ])
            ->headerActions([
                Tables\Actions\AttachAction::make()
                    ->preloadRecordSelect(),
                    // ->form(fn (Tables\Actions\AttachAction $attachAction): array => [
                    //     $attachAction->getRecordSelect(),
                    //     Forms\Components\Select::make('name'),
                    // ]),
            ])
    }
}
namespace App\Filament\Driver\Resources\CarOwnerResource\RelationManagers;

class CarFeaturesRelationManager extends RelationManager
{
    protected static string $relationship = 'carFeatures';

    public function table(Table $table): Table
    {
        return $table
            ->recordTitleAttribute('name')
            ->columns([
                        ...
                    }),
            ])
            ->headerActions([
                Tables\Actions\AttachAction::make()
                    ->preloadRecordSelect(),
                    // ->form(fn (Tables\Actions\AttachAction $attachAction): array => [
                    //     $attachAction->getRecordSelect(),
                    //     Forms\Components\Select::make('name'),
                    // ]),
            ])
    }
}
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

FILAMENT MANYTOMANY RELATIONSHIP ISSUE:
FilamentFFilament / ❓┊help
2y ago
ManyToMany Relationship Attach Action on Custom Table
FilamentFFilament / ❓┊help
8mo ago
AttachAction select different relationship?
FilamentFFilament / ❓┊help
2y ago
Nested Resources with manyToMany relationship
FilamentFFilament / ❓┊help
2y ago