psycho_cfh
psycho_cfh
FFilament
Created by psycho_cfh on 1/25/2024 in #❓┊help
Navigation Builder
Hi, How can add navigation builder in filament v3
2 replies
FFilament
Created by psycho_cfh on 12/14/2023 in #❓┊help
morphedByMany in RelationManager error without allowDuplicates
Hi, RelationManager support morphedByMany relationship with pivot table ?
4 replies
FFilament
Created by psycho_cfh on 12/11/2023 in #❓┊help
morphToMany issue with RelationManager
Hi, i have a problem with the relation manager when i try to associate a Product Model to a Order Model, the query give me an error "Column not found: 1054 Unknown column 'products.order_id' in 'field list'" what am I doing wrong? Thanks This is my model code:
class Order extends Model
{
public function products()
{
return $this->morphedByMany(Product::class, 'order_item');
}
}
class Order extends Model
{
public function products()
{
return $this->morphedByMany(Product::class, 'order_item');
}
}
class Product extends Model implements Purchasable
{
public function orders()
{
return $this->morphToMany(Order::class, 'order_item');
}

}
class Product extends Model implements Purchasable
{
public function orders()
{
return $this->morphToMany(Order::class, 'order_item');
}

}
class OrderItem extends Model
{
public function order_item()
{
return $this->morphTo();
}
}
class OrderItem extends Model
{
public function order_item()
{
return $this->morphTo();
}
}
class ProductsRelationManager extends RelationManager
{
protected static string $relationship = 'products';

protected static ?string $inverseRelationship = 'orders';

public function form(Form $form): Form
{
return $form
->schema([]);
}

public function table(Table $table): Table
{
return $table
->recordTitleAttribute('order_id')
->columns([
Tables\Columns\TextColumn::make('name'),
])
->filters([
//
])
->headerActions([
Tables\Actions\AssociateAction::make()->form(fn (AssociateAction $action): array => [
$action->getRecordSelect(),
Forms\Components\Select::make('name')
->options(Product::all()->pluck('name', 'id'))
->required(),
]),
])
->actions([
Tables\Actions\DissociateAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DissociateBulkAction::make(),
Tables\Actions\DeleteBulkAction::make(),
]),
]);
}


}
class ProductsRelationManager extends RelationManager
{
protected static string $relationship = 'products';

protected static ?string $inverseRelationship = 'orders';

public function form(Form $form): Form
{
return $form
->schema([]);
}

public function table(Table $table): Table
{
return $table
->recordTitleAttribute('order_id')
->columns([
Tables\Columns\TextColumn::make('name'),
])
->filters([
//
])
->headerActions([
Tables\Actions\AssociateAction::make()->form(fn (AssociateAction $action): array => [
$action->getRecordSelect(),
Forms\Components\Select::make('name')
->options(Product::all()->pluck('name', 'id'))
->required(),
]),
])
->actions([
Tables\Actions\DissociateAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DissociateBulkAction::make(),
Tables\Actions\DeleteBulkAction::make(),
]),
]);
}


}
3 replies