filamentphp / filament

A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS.

Home Page:https://filamentphp.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

custom one to one column

falcon-cold opened this issue · comments

Package

filament/tables

Package Version

3.2

Laravel Version

v11.0

Livewire Version

v3

PHP Version

8.3

Problem description

Custom fields display different columns according to different tabs,

public function getTabs(): array
	{
		$restuls = [
			null => Tab::make(__('All')),
		];

		$items = CustomField::queryAllTypeFor('user_profile', 'ASC');

		foreach ($items as $entry) {
			$restuls[$entry->getSlug()] = Tab::make()
				->query(
					fn ($query) => $query->whereHas(
						$entry->getSlug(),
						// fn ($query) => $query->where('type_entry', $entry->getSlug())
					)
				)->extraAttributes([
					'slug'=> $entry->getSlug(),
				])
				->label($entry->getName());
		}

		return $restuls;
	}


public function table(Table $table): Table
	{
		$resource = static::getResource();
		$resource::customFieldsSlugConfig($this->activeTab);

		return $resource::table($table);
	}

Now, $this->activeTab needs to be clicked twice to display the results properly

Expected behavior

The list page displays all custom field information

Steps to reproduce

my model

public function __call($method, $parameters)
	{
		if (str_starts_with($method, 'custom')) {

			$entry = CustomField::query()
				->select('slug', 'entry_class')
				->where('entry_type', 'user_profile')
				->where('slug', $method)
				->first();
			return $this->hasOne($entry->entry_class, 'user_id');
		}

		return parent::__call($method, $parameters);
	}

my userResource.php

public static function table(Table $table): Table
	{
		return $table
			->columns([
				MediaColumn::make('materialImage'),
				BadgeableColumn::make('name')
					->suffixBadges([
						Badge::make('unit')
							->color('success')
							->visible(fn(Model $record) => $record->created_at?->timestamp > (time() - 86400)),
					])->searchable()->copyable()->sortable()->asPills(),
				
				...static::previewTabForCustomExpand()
			])
			->filters([
				Tables\Filters\TrashedFilter::make(),
				// ...
			])
			->actions([
				//...
			])
			->bulkActions([
				//...
			])
			->deferLoading();
	}
public static function previewTabForCustomExpand(): array
	{
		$custom = CustomField::queryTypeFor('user_profile', request()->activeTab);

		if (! $custom) {
			return [];
		}

		// dd(Material::query()->where('type_entry', request()->activeTab)->with(request()->activeTab)->first());

		$items = $custom->fieldItems->getColumnComponents($custom->getSlug());

		return $items;
	}

Reproduction repository (issue will be closed if this is not valid)

https://github.com/

Relevant log output

No response

Donate 💰 to fund this issue

  • You can donate funding to this issue. We receive the money once the issue is completed & confirmed by you.
  • 100% of the funding will be distributed between the Filament core team to run all aspects of the project.
  • Thank you in advance for helping us make maintenance sustainable!
Fund with Polar

Missing reproduction repository.