techenby
techenby
FFilament
Created by techenby on 9/14/2023 in #❓┊help
Action button has no background in Livewire component
Looks like I missed @filamentStyles and @filamentScripts in my layout file.
2 replies
FFilament
Created by Mdk on 7/5/2023 in #❓┊help
How to display and update pivot field in attach/edit form?
On the form I used task but on the table I used pivot.task
6 replies
FFilament
Created by Mdk on 7/5/2023 in #❓┊help
How to display and update pivot field in attach/edit form?
I recently did this for a project. I had a jobs table and a job_user table with a task on the job_user table. Here's what my relation manager looked like:
<?php

namespace App\Filament\Resources\JobResource\RelationManagers;

use App\Models\Job;
use Filament\Forms\Components\Select;
use Filament\Resources\Form;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Resources\Table;
use Filament\Tables\Columns\TextColumn;

class UsersRelationManager extends RelationManager
{
protected static string $relationship = 'users';

protected static ?string $recordTitleAttribute = 'name';

public static function form(Form $form): Form
{
return $form
->schema([
Select::make('task')
->options([
Job::EXCAVATE => 'Locate and Excavate',
Job::BACKFILL => 'Backfill and Clean',
'other' => 'Other',
])
->required(),
]);
}

public static function table(Table $table): Table
{
return $table
->columns([
TextColumn::make('name')
->label('Employee'),
TextColumn::make('pivot.task')
->enum([
Job::EXCAVATE => 'Locate and Excavate',
Job::BACKFILL => 'Backfill and Clean',
'other' => 'Other',
])
->label('Assigned Task'),
])
->filters([
//
])
->actions([
//
])
->bulkActions([
//
]);
}
}
<?php

namespace App\Filament\Resources\JobResource\RelationManagers;

use App\Models\Job;
use Filament\Forms\Components\Select;
use Filament\Resources\Form;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Resources\Table;
use Filament\Tables\Columns\TextColumn;

class UsersRelationManager extends RelationManager
{
protected static string $relationship = 'users';

protected static ?string $recordTitleAttribute = 'name';

public static function form(Form $form): Form
{
return $form
->schema([
Select::make('task')
->options([
Job::EXCAVATE => 'Locate and Excavate',
Job::BACKFILL => 'Backfill and Clean',
'other' => 'Other',
])
->required(),
]);
}

public static function table(Table $table): Table
{
return $table
->columns([
TextColumn::make('name')
->label('Employee'),
TextColumn::make('pivot.task')
->enum([
Job::EXCAVATE => 'Locate and Excavate',
Job::BACKFILL => 'Backfill and Clean',
'other' => 'Other',
])
->label('Assigned Task'),
])
->filters([
//
])
->actions([
//
])
->bulkActions([
//
]);
}
}
6 replies
FFilament
Created by techenby on 6/27/2023 in #❓┊help
How to test a Table header action on a Relationship Manager?
Gotcha! Thank you 🙂
4 replies
FFilament
Created by techenby on 4/13/2023 in #❓┊help
Can I have dynamic columns or inputs in resource?
19 replies
FFilament
Created by techenby on 4/13/2023 in #❓┊help
Can I have dynamic columns or inputs in resource?
I'd still love to hear someone else's take on if there's a better way to do this.
19 replies
FFilament
Created by techenby on 4/13/2023 in #❓┊help
Can I have dynamic columns or inputs in resource?
I was able to accomplish what I wanted, but I'm not super happy with it. I'm using the uri of the request to figure out what model I'm looking at and fetch what I need.
public static function getFormColumns()
{
$uri = request()->getRequestUri();
if (Str::of($uri)->startsWith('/livewire')) {
$data = request()->json()->get('serverMemo')['dataMeta']['models'];
$id = isset($data['record']) ? $data['record']['id'] : $data['ownerRecord']['id'];
} else {
$id = explode('/', $uri)[3];
}
$form = ModelsForm::where('event_id', $id)->where('type', 'workshop')->first();

if ($form) {
return collect($form->settings->searchable)
->map(function ($id) {
return TextColumn::make('answers.' . $id)
->label(strtoupper($id))
->toggleable();
});
}
}
public static function getFormColumns()
{
$uri = request()->getRequestUri();
if (Str::of($uri)->startsWith('/livewire')) {
$data = request()->json()->get('serverMemo')['dataMeta']['models'];
$id = isset($data['record']) ? $data['record']['id'] : $data['ownerRecord']['id'];
} else {
$id = explode('/', $uri)[3];
}
$form = ModelsForm::where('event_id', $id)->where('type', 'workshop')->first();

if ($form) {
return collect($form->settings->searchable)
->map(function ($id) {
return TextColumn::make('answers.' . $id)
->label(strtoupper($id))
->toggleable();
});
}
}
Then in the table I have this:
return $table
->columns([
TextColumn::make('id')->label('Proposal ID'),
TextColumn::make('status'),
TextColumn::make('name'),
...static::getFColumns(),
])
return $table
->columns([
TextColumn::make('id')->label('Proposal ID'),
TextColumn::make('status'),
TextColumn::make('name'),
...static::getFColumns(),
])
19 replies
FFilament
Created by techenby on 4/13/2023 in #❓┊help
Can I have dynamic columns or inputs in resource?
(Eventually I'd like to use FormBuilder to dynamically generate the form on the frontend but that's a project for a different day)
19 replies
FFilament
Created by Ayman Alhattami on 4/13/2023 in #❓┊help
Can I use Form layouts like FieldSet with table filter ?
Something like this maybe?
->filters([
Filter::make('id')->translateLabel()
->form([
Fieldset::make('hi')->schema([
TextInput::make('id'),
TextInput::make('id'),
TextInput::make('id'),
}),
])->query(function (Builder $query, array $data): Builder {
if (optional($data)['id']) {
return $query->where('id', $data['id']);
} else {
return $query;
}
}),
]);
->filters([
Filter::make('id')->translateLabel()
->form([
Fieldset::make('hi')->schema([
TextInput::make('id'),
TextInput::make('id'),
TextInput::make('id'),
}),
])->query(function (Builder $query, array $data): Builder {
if (optional($data)['id']) {
return $query->where('id', $data['id']);
} else {
return $query;
}
}),
]);
17 replies
FFilament
Created by Ayman Alhattami on 4/13/2023 in #❓┊help
Can I use Form layouts like FieldSet with table filter ?
Try putting the Fieldset inside the ->form([
17 replies
FFilament
Created by techenby on 4/13/2023 in #❓┊help
Can I have dynamic columns or inputs in resource?
I can iterate over each item in the answers column or iterate over the ids grabbed from the Survey. But that still leads me to two questions: 1: how to foreach or map over a value to get n number of columns 2. How to get the $record or $ownerRecord to pass into the foreach or map
19 replies
FFilament
Created by techenby on 4/13/2023 in #❓┊help
Can I have dynamic columns or inputs in resource?
I'm working on a ResponsesRelationshipManager that is on the SurveyResource and I'd like to have a column for favorite-color and favorite-cake
19 replies
FFilament
Created by techenby on 4/13/2023 in #❓┊help
Can I have dynamic columns or inputs in resource?
19 replies
FFilament
Created by techenby on 4/13/2023 in #❓┊help
Can I have dynamic columns or inputs in resource?
I hope that makes sense 😬
19 replies
FFilament
Created by techenby on 4/13/2023 in #❓┊help
Can I have dynamic columns or inputs in resource?
Depending on which survey I click into, the ids for the user's answer can vary a lot. So I'm trying to iterate over the questions and get the answer and put it into a column.
19 replies
FFilament
Created by techenby on 4/13/2023 in #❓┊help
Can I have dynamic columns or inputs in resource?
What I'm working on now is displaying the answers to the survey questions in a table.
19 replies
FFilament
Created by techenby on 4/13/2023 in #❓┊help
Can I have dynamic columns or inputs in resource?
I have a survey model, that folks can build up a form for users to fill out.
19 replies
FFilament
Created by techenby on 4/13/2023 in #❓┊help
Can I have dynamic columns or inputs in resource?
It varies per parent, maybe if I add more context lol.
19 replies
FFilament
Created by techenby on 4/13/2023 in #❓┊help
Can I have dynamic columns or inputs in resource?
Like normally I'd foreach over $this->record but only being able to access the owner record in a closure makes it confusing, and makes my brain melt a little bit
19 replies
FFilament
Created by techenby on 4/13/2023 in #❓┊help
Can I have dynamic columns or inputs in resource?
Since it's in a relationship manager, it wouldn't vary per record. The values for the potential keys are stored in the parent, but how do I loop through an array to generate many TextColumn(s)
19 replies