Roland Barkóczi
Roland Barkóczi
FFilament
Created by Roland Barkóczi on 10/31/2024 in #❓┊help
How should I define the exportAction exporter class in order to export hasMany relation?
Hello awcodes, thanks, finally I imploded the prices into one field separated by a pipe, and import back this way. The main problem here, that the getColumns function is static, and it's content can't be change based on options.
5 replies
FFilament
Created by Roland Barkóczi on 10/17/2024 in #❓┊help
How to manage ManyToMany relation in TableBuilder and FormBuilder?
actually the ->default() will show any data in the cell, even if the referenced attribute does not exists
47 replies
FFilament
Created by Roland Barkóczi on 10/17/2024 in #❓┊help
How to manage ManyToMany relation in TableBuilder and FormBuilder?
thanks again for your support!
47 replies
FFilament
Created by Roland Barkóczi on 10/17/2024 in #❓┊help
How to manage ManyToMany relation in TableBuilder and FormBuilder?
actually I use this data model for ages in my legacy e-commerce projects (even not laravel projects)
47 replies
FFilament
Created by Roland Barkóczi on 10/17/2024 in #❓┊help
How to manage ManyToMany relation in TableBuilder and FormBuilder?
the form won't be a problem, I create some fancy component for it
47 replies
FFilament
Created by Roland Barkóczi on 10/17/2024 in #❓┊help
How to manage ManyToMany relation in TableBuilder and FormBuilder?
yeah, use case is expecting here ~20 product/service per vendor
47 replies
FFilament
Created by Roland Barkóczi on 10/17/2024 in #❓┊help
How to manage ManyToMany relation in TableBuilder and FormBuilder?
I gonna debug it, but I gonna figure out some caching these data in a Redis server
47 replies
FFilament
Created by Roland Barkóczi on 10/17/2024 in #❓┊help
How to manage ManyToMany relation in TableBuilder and FormBuilder?
Anyway, awcodes, thank you so much to try to help me. You're great!
47 replies
FFilament
Created by Roland Barkóczi on 10/17/2024 in #❓┊help
How to manage ManyToMany relation in TableBuilder and FormBuilder?
The default() just inject the $record to the callback function. Of course the 'price_1' still not exists therefore it cannot display anything, but in the default() function I can query the necessary data
47 replies
FFilament
Created by Roland Barkóczi on 10/17/2024 in #❓┊help
How to manage ManyToMany relation in TableBuilder and FormBuilder?
No description
47 replies
FFilament
Created by Roland Barkóczi on 10/17/2024 in #❓┊help
How to manage ManyToMany relation in TableBuilder and FormBuilder?
yeah, it's okay.
47 replies
FFilament
Created by Roland Barkóczi on 10/17/2024 in #❓┊help
How to manage ManyToMany relation in TableBuilder and FormBuilder?
yeah, thats the problem. I can query the price if I iterate through the pricelists. My first idea was using the formatStateUsing() but if in case I add a non-existing or empty attribute to the TextColumn::make('xxxx') it shows nothing, and even the formatStateUsing is not called
47 replies
FFilament
Created by Roland Barkóczi on 10/17/2024 in #❓┊help
How to manage ManyToMany relation in TableBuilder and FormBuilder?
No description
47 replies
FFilament
Created by Roland Barkóczi on 10/17/2024 in #❓┊help
How to manage ManyToMany relation in TableBuilder and FormBuilder?
No description
47 replies
FFilament
Created by Roland Barkóczi on 10/17/2024 in #❓┊help
How to manage ManyToMany relation in TableBuilder and FormBuilder?
Sure:
->columns([
TextColumn::make('name')
->label(__('Name'))
->description(fn(Product $record): string => __('Short name') . ": " . $record->short_name . " | " . __('SKU') . ": " . ($record->sku ?? '-')),
TextColumn::make('category.name')
->label(__('Category')),
ToggleColumn::make('is_active')
->label(__('Active'))->toggleable(),
...array_map(
fn(Pricelist $pricelist) =>
TextColumn::make('pricelists.' . $pricelist->id . ".price")
->label($pricelist->name),
$this->getOwnerRecord()->pricelists()->get()->all()
)
])
->columns([
TextColumn::make('name')
->label(__('Name'))
->description(fn(Product $record): string => __('Short name') . ": " . $record->short_name . " | " . __('SKU') . ": " . ($record->sku ?? '-')),
TextColumn::make('category.name')
->label(__('Category')),
ToggleColumn::make('is_active')
->label(__('Active'))->toggleable(),
...array_map(
fn(Pricelist $pricelist) =>
TextColumn::make('pricelists.' . $pricelist->id . ".price")
->label($pricelist->name),
$this->getOwnerRecord()->pricelists()->get()->all()
)
])
47 replies
FFilament
Created by Roland Barkóczi on 10/17/2024 in #❓┊help
How to manage ManyToMany relation in TableBuilder and FormBuilder?
No, because the pivot table connects only these two tables. I can't see any polymorphic behaviour what is described here: https://laravel.com/docs/11.x/eloquent-relationships#many-to-many-polymorphic-relations
47 replies
FFilament
Created by Roland Barkóczi on 10/17/2024 in #❓┊help
How to manage ManyToMany relation in TableBuilder and FormBuilder?
It should be dynamic. I tried, pricelist_2.price but does not work. I want to display somehow the following result in data table:
$product->pricelists()->where('pricelist_id', 2)->first()->pivot->price
$product->pricelists()->where('pricelist_id', 2)->first()->pivot->price
47 replies
FFilament
Created by Roland Barkóczi on 10/17/2024 in #❓┊help
How to manage ManyToMany relation in TableBuilder and FormBuilder?
Hello Awcodes, I think this is a pure many to many relation: Product -> ProductPrice (Pivot) <- PriceList I modified the Product model, and added:
public function pricelists(): BelongsToMany
{
return $this->belongsToMany(Pricelist::class, 'vendor_product_prices', 'product_id', 'pricelist_id')
->withPivot('price');
}
public function pricelists(): BelongsToMany
{
return $this->belongsToMany(Pricelist::class, 'vendor_product_prices', 'product_id', 'pricelist_id')
->withPivot('price');
}
also the Pricelist model:
public function products(): BelongsToMany
{
return $this->belongsToMany(Product::class, 'vendor_product_prices', 'pricelist_id', 'product_id');
}
public function products(): BelongsToMany
{
return $this->belongsToMany(Product::class, 'vendor_product_prices', 'pricelist_id', 'product_id');
}
Question still open: how can I implement The following table:
name | Retail price | Discount price | ... |
---------------------------------------------------
Product 1 | 1000.000. |800.0000. | ....
---------------------------------------------------
Product 2 | 1200.000. |1000.0000. | ....
name | Retail price | Discount price | ... |
---------------------------------------------------
Product 1 | 1000.000. |800.0000. | ....
---------------------------------------------------
Product 2 | 1200.000. |1000.0000. | ....
47 replies
FFilament
Created by Roland Barkóczi on 10/17/2024 in #❓┊help
How to manage ManyToMany relation in TableBuilder and FormBuilder?
If I add debug($key) to the magic __get() function, it even not print the price_2, all the other getter (eg: name, sku, category_id) are listed in the debugbar
47 replies
FFilament
Created by Roland Barkóczi on 10/17/2024 in #❓┊help
How to manage ManyToMany relation in TableBuilder and FormBuilder?
I add the following function to the Product model
public function __get($key)
{
//if $key matches price_pricelist, return the price
if (preg_match('/^price_(\d+)$/', $key, $matches)) {
return $this->price($matches[1])->price;
}

return parent::__get($key);
}
public function __get($key)
{
//if $key matches price_pricelist, return the price
if (preg_match('/^price_(\d+)$/', $key, $matches)) {
return $this->price($matches[1])->price;
}

return parent::__get($key);
}
Tinker sais:
> $product->price_2
= "500.0000"
> $product->price_2
= "500.0000"
But if I add this to the TextColumn::make('price_2"), it does not show.
47 replies