ManyToMany Relationship on AttachAction
I am trying to use AttachAction, and I am trying to implement it. But instead i got an error
error:
model:
Call to undefined method App\Models\Car\Feature::carOwners()
Call to undefined method App\Models\Car\Feature::carOwners()
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'),
// ]),
])
}
}
3 Replies
up
The issue might be that you are using a 'carOwners' method that doesn’t exist in your model
I was ignoring the error. cause I was so sure that I named the function correctly.. Thank you.
just literally change the carFeatures in Feature Model to 'carOwners' fixed it.