ouch
ouch
FFilament
Created by ouch on 3/2/2024 in #❓┊help
Set relationship via $set
I have create form, where I can input catalog number (gets an item) and some fields are autofilled, but now i struggle with loading existing images that are associated with main item. And i want them to load if the existing catalog is inputed. Items --< Sizes So i was thinking that i could set relationship item, and somehow load images. But i couldnt make it to set the relationship.
TextInput::make('catalog')
->label(__('filament.warehouse.product.catalog'))
->minLength(3)
->live()
->required()
->debounce(500)
->afterStateUpdated(function (Get $get, Set $set, $state) {
if (!empty($state)){
$query = Item::where('catalog', $state);
if ($query->exists()){
$item = $query->get()->first();
//setting relation?
}
}
})
->datalist(fn() => Item::distinct('catalog')->pluck('catalog')->toArray()),

Group::make()
->relationship('item')
->schema([
Forms\Components\SpatieMediaLibraryFileUpload::make('images')
->imagePreviewHeight('125')
->reactive()
->image()
->multiple()
->optimize('webp')
->resize(30)
->conversion('img')
->label('')
->collection(Item::ITEM_COLLECTION_NAME)
->directory('products')
->imageEditor()
->enableReordering(),
])
TextInput::make('catalog')
->label(__('filament.warehouse.product.catalog'))
->minLength(3)
->live()
->required()
->debounce(500)
->afterStateUpdated(function (Get $get, Set $set, $state) {
if (!empty($state)){
$query = Item::where('catalog', $state);
if ($query->exists()){
$item = $query->get()->first();
//setting relation?
}
}
})
->datalist(fn() => Item::distinct('catalog')->pluck('catalog')->toArray()),

Group::make()
->relationship('item')
->schema([
Forms\Components\SpatieMediaLibraryFileUpload::make('images')
->imagePreviewHeight('125')
->reactive()
->image()
->multiple()
->optimize('webp')
->resize(30)
->conversion('img')
->label('')
->collection(Item::ITEM_COLLECTION_NAME)
->directory('products')
->imageEditor()
->enableReordering(),
])
1 replies
FFilament
Created by ouch on 11/22/2023 in #❓┊help
How to show array key in TextColumn
Hi i have Variant model whre i save json in format like this {"Name":"Value"} and i'm casting it
protected $casts = [
'variant_attributes_json' => 'array',
];
protected $casts = [
'variant_attributes_json' => 'array',
];
How could i display key into textcolumn or other column? Because if i put it into textCol it in state is only value
Tables\Columns\TextColumn::make('variant_attributes_json')
Tables\Columns\TextColumn::make('variant_attributes_json')
ps: I'm new to filament 🙂
9 replies
FFilament
Created by ouch on 11/10/2023 in #❓┊help
Custom Page -> open modal from code (dispatch)
I have custom page and i need open modal in certain condition. Is there better way than this, cuz i feel like this is terrible. And i bet that there is better way to do it, as well when i click at either of button it loads for 500ms is there way to skip animation?
class ScanProducts extends Page
{
#[Rule('min:3', message: 'Minimální počet znaků 3')]
#[Rule('required',message: 'Čárový kód musí být vyplněn.')]
public $barcode = '';

public function form(Form $form): Form
{
return $form
->schema([
TextInput::make('barcode')...
]);
}

public function scan()
{
$product = Item::where('barcode',$this->barcode)->first();
if(!$product && $this->barcode) {
/////// OPENING MODAL HERE
$this->dispatch('open-modal', id: 'create-product');
/*Some other logic*/
}

public function redirectCreateProduct()
{
return $this->redirect( ItemResource::getUrl('create'));
}
public function closeModal()
{
$this->dispatch('close-modal', id: 'create-product');
}
}
class ScanProducts extends Page
{
#[Rule('min:3', message: 'Minimální počet znaků 3')]
#[Rule('required',message: 'Čárový kód musí být vyplněn.')]
public $barcode = '';

public function form(Form $form): Form
{
return $form
->schema([
TextInput::make('barcode')...
]);
}

public function scan()
{
$product = Item::where('barcode',$this->barcode)->first();
if(!$product && $this->barcode) {
/////// OPENING MODAL HERE
$this->dispatch('open-modal', id: 'create-product');
/*Some other logic*/
}

public function redirectCreateProduct()
{
return $this->redirect( ItemResource::getUrl('create'));
}
public function closeModal()
{
$this->dispatch('close-modal', id: 'create-product');
}
}
pages blade
...
<x-filament::modal id="create-product" icon="heroicon-o-information-circle">
{{--CONTENT--}}
<x-slot name="footerActions">
<x-filament::button
color="gray"
wire:click="closeModal()"
>
Close
</x-filament::button>
<x-filament::button
wire:click="redirectCreateProduct()"
>
Create
</x-filament::button>
</x-slot>
</x-filament::modal>
<x-filament-actions::modals />
...
<x-filament::modal id="create-product" icon="heroicon-o-information-circle">
{{--CONTENT--}}
<x-slot name="footerActions">
<x-filament::button
color="gray"
wire:click="closeModal()"
>
Close
</x-filament::button>
<x-filament::button
wire:click="redirectCreateProduct()"
>
Create
</x-filament::button>
</x-slot>
</x-filament::modal>
<x-filament-actions::modals />
1 replies
FFilament
Created by ouch on 11/7/2023 in #❓┊help
Many to Many in Tables in livewire component
Hey guys I'm newbie in filament and livewire and I'm confused with relationships. I have filament tables as stand alone package on livewire without panel, and i have a problem with many to many relationship Order >--< Status, and I want to use SelectColumn. And I'm confused how to make it work. Because i dont use panel so i can't create realation ship manager correct? Model Order
public function statuses(): BelongsToMany
{
return $this->belongsToMany(
Status::class,
'order_status',
'order_id',
'status_id'
)->withTimestamps();
}
public function statuses(): BelongsToMany
{
return $this->belongsToMany(
Status::class,
'order_status',
'order_id',
'status_id'
)->withTimestamps();
}
Inside table - I know that it does not get last element but honestly I'm lost now.
SelectColumn::make('statuses.name')
->label('Stav')
->options(Status::pluck('name')
->toArray())
SelectColumn::make('statuses.name')
->label('Stav')
->options(Status::pluck('name')
->toArray())
5 replies