techenby
techenby
FFilament
Created by techenby on 9/14/2023 in #❓┊help
Action button has no background in Livewire component
I have created a full-page Livewire component and followed the documentation for using an Action in a Livewire component.
<?php

namespace App\Livewire\App;

use App\Models\Event;
use Filament\Actions\Action;
use Filament\Actions\Concerns\InteractsWithActions;
use Filament\Actions\Contracts\HasActions;
use Filament\Forms\Components\RichEditor;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Livewire\Component;

class MessageBoard extends Component implements HasForms, HasActions
{
use InteractsWithActions;
use InteractsWithForms;

public Event $event;

public function render()
{
return view('livewire.app.message-board');
}

public function createAction(): Action
{
return Action::make('create')
->button()
->color('primary')
->form([
TextInput::make('title')->required(),
RichEditor::make('content')->required(),
])
->action(fn () => $this->post->delete());
}
}
<?php

namespace App\Livewire\App;

use App\Models\Event;
use Filament\Actions\Action;
use Filament\Actions\Concerns\InteractsWithActions;
use Filament\Actions\Contracts\HasActions;
use Filament\Forms\Components\RichEditor;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Livewire\Component;

class MessageBoard extends Component implements HasForms, HasActions
{
use InteractsWithActions;
use InteractsWithForms;

public Event $event;

public function render()
{
return view('livewire.app.message-board');
}

public function createAction(): Action
{
return Action::make('create')
->button()
->color('primary')
->form([
TextInput::make('title')->required(),
RichEditor::make('content')->required(),
])
->action(fn () => $this->post->delete());
}
}
When viewing the page, the button has no background. It looks like the var(--primary-600) is not found for the bg-custom-600; I have no idea how to get that working.
2 replies
FFilament
Created by techenby on 6/27/2023 in #❓┊help
How to test a Table header action on a Relationship Manager?
I have the following test:
/** @test */
public function can_assign_users_to_job_on_view_page()
{
$admin = User::factory()->create();
$job = Job::factory()->create();
$employee = User::factory()->create();

Livewire::actingAs($admin)
->test(UsersRelationManager::class, ['ownerRecord' => $job])
->assertSuccessful()
->callPageAction(AttachAction::class, [
'recordId' => $employee->id,
'task' => Job::EXCAVATE,
]);

$this->assertDatabaseHas('job_user', [
'job_id' => $job->id,
'user_id' => $employee->id,
'task' => Job::EXCAVATE,
]);
}
/** @test */
public function can_assign_users_to_job_on_view_page()
{
$admin = User::factory()->create();
$job = Job::factory()->create();
$employee = User::factory()->create();

Livewire::actingAs($admin)
->test(UsersRelationManager::class, ['ownerRecord' => $job])
->assertSuccessful()
->callPageAction(AttachAction::class, [
'recordId' => $employee->id,
'task' => Job::EXCAVATE,
]);

$this->assertDatabaseHas('job_user', [
'job_id' => $job->id,
'user_id' => $employee->id,
'task' => Job::EXCAVATE,
]);
}
I don't think callPageAction is correct since if I use it, I get the following error: UsersRelationManager::getCachedAction does not exist. If I use callTableAction I get the following error: RelationManager::getTableRecord(): Argument #1 ($key) must be of type ?string, array given, Which makes sense, but what should I use?
4 replies
FFilament
Created by techenby on 4/13/2023 in #❓┊help
Can I have dynamic columns or inputs in resource?
I have a model that has a json column with key value pairs. However the keys are not constant and generated by user input. Is it possible to have one text column per entry? I was thinking something like this but PHP doesn't like it:
return $table
->columns([
TextColumn::make('id')->label('Proposal ID'),
TextColumn::make('status'),
TextColumn::make('name'),
...function ($record): array {
return $record->answers->map(function ($answer) {
return TextColumn::make($answer);
});
},
])
...
return $table
->columns([
TextColumn::make('id')->label('Proposal ID'),
TextColumn::make('status'),
TextColumn::make('name'),
...function ($record): array {
return $record->answers->map(function ($answer) {
return TextColumn::make($answer);
});
},
])
...
19 replies
FFilament
Created by techenby on 3/3/2023 in #❓┊help
Customize Widget height instead of width
Is it possible to define a widget's height instead of width? i.e. tell a widget to span 2 rows instead of one? https://filamentphp.com/docs/2.x/admin/dashboard/getting-started#customizing-widget-width
11 replies