Skip to content

Commit

Permalink
fix: parent name bug category form. rename variable to
Browse files Browse the repository at this point in the history
  • Loading branch information
mckenziearts committed Dec 5, 2024
1 parent 5fb5d8a commit 35f3aed
Show file tree
Hide file tree
Showing 5 changed files with 77,285 additions and 20 deletions.
10,685 changes: 10,684 additions & 1 deletion packages/admin/public/shopper.css

Large diffs are not rendered by default.

66,597 changes: 66,584 additions & 13 deletions packages/admin/public/shopper.js

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions packages/admin/src/Livewire/SlideOvers/CategoryForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,13 @@ public function form(Form $form): Form
Components\Hidden::make('slug'),
Components\Select::make('parent_id')
->label(__('shopper::forms.label.parent'))
->relationship('parent', 'name', fn (Builder $query) => $query->where('is_enabled', true))
->getOptionLabelFromRecordUsing(
fn ($model) => $model->parent
? "{$model->parent->name} / {$model->name}"
: $model->name
->relationship(
name: 'parent',
titleAttribute: 'name',
modifyQueryUsing: fn (Builder $query) => $query->where('is_enabled', true)
)
->getOptionLabelFromRecordUsing(fn ($record) => $record->getLabelOptionName())
->preload()
->searchable()
->placeholder(__('shopper::pages/categories.empty_parent')),
Components\Toggle::make('is_enabled')
Expand Down
10 changes: 10 additions & 0 deletions packages/core/src/Models/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ public function updateStatus(bool $status = true): void
$this->save();
}

/**
* Use to display custom label into filament relationship select form component
*/
public function getLabelOptionName(): string
{
return $this->parent
? $this->parent->getLabelOptionName() . ' / ' . $this->name
: $this->name;
}

public function scopeEnabled(Builder $query): Builder
{
return $query->where('is_enabled', true);
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/Models/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

namespace Shopper\Core\Models;

use Database\Factories\CollectionFactory;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\MorphToMany;
use Shopper\Core\Database\Factories\CollectionFactory;
use Shopper\Core\Enum\CollectionType;
use Shopper\Core\Traits\HasMedia;
use Shopper\Core\Traits\HasSlug;
Expand Down

0 comments on commit 35f3aed

Please sign in to comment.