Patrick
Patrick
FFilament
Created by Patrick on 9/11/2024 in #❓┊help
FBlog won't save post when TiptipEditor output is set to JSON.
I'm trying out the blog plugin for filament. I already had Tiptap editor installed and changed the config to save output as JSON. This will result in an "array to string conversion" when trying to save the post. Added the body of the post to the $casts as array solves it, but since the Post model resides in the vendor folder I can't edit this. Is there a way to work around this?
8 replies
FFilament
Created by Patrick on 6/21/2024 in #❓┊help
Can not add table to a component
I have a custom component where i want to display a table. Implemented the trait and interface:
class ConfirmMailing extends Component implements HasForms, HasTable
{
use InteractsWithTable;
use InteractsWithForms;
class ConfirmMailing extends Component implements HasForms, HasTable
{
use InteractsWithTable;
use InteractsWithForms;
Now the problem is adding the table method, this expects to return a Table , but the underlying trait expects Static as return type. This is according to the docs:
public function table(Table $table): Table
{
return $table
->query(Mailing::query())
->columns([
TextColumn::make('id'),
])
->filters([
// ...
])
->actions([
// ...
])
->bulkActions([
// ...
]);
}
public function table(Table $table): Table
{
return $table
->query(Mailing::query())
->columns([
TextColumn::make('id'),
])
->filters([
// ...
])
->actions([
// ...
])
->bulkActions([
// ...
]);
}
And when checking the trait HasTables, the method is like this:
interface HasTable
{
public function table(Table $table): static;
interface HasTable
{
public function table(Table $table): static;
So this will result in the following error:
Declaration of App\Livewire\Tables\ConfirmMailing::table(Filament\Tables\Table $table) must be compatible with Filament\Tables\Actions\Contracts\HasTable::table
Declaration of App\Livewire\Tables\ConfirmMailing::table(Filament\Tables\Table $table) must be compatible with Filament\Tables\Actions\Contracts\HasTable::table
Am I missing something or is this a bug?
4 replies
FFilament
Created by Patrick on 3/7/2024 in #❓┊help
Show table action only when a specific filter is set
I would like to display a table action, but only when a specific filter is selected. This works on the first request and there is a filter value in the GET:
Tables\Actions\Action::make('testactio')
->visible(function(){
$filter = request()->get('tableFilters');
if(isset($filter['verplichte_cursus']) && $filter['verplichte_cursus']){
return true;
}
Tables\Actions\Action::make('testactio')
->visible(function(){
$filter = request()->get('tableFilters');
if(isset($filter['verplichte_cursus']) && $filter['verplichte_cursus']){
return true;
}
But won't work when we select the filter after the page loads. I tried injecting
$get
$get
but it can't resolve that. Is there a way to do this?
3 replies
FFilament
Created by Patrick on 3/1/2024 in #❓┊help
Setting a field value from an action
This is my action: Actions\Action::make('gespreksverslag_herschrijven') ->label('Gespreksverslag herschrijven') ->icon('heroicon-o-pencil') ->action(function(){

$originalText = $this->data['conversation_report_original']; $service = new RewriteTextWithGPTService(); $rewrittenText = $service->handle(static::$prompt, $originalText); $this->form->fill([ 'conversation_report_gpt' => $rewrittenText, ], true);
}),
Im trying to fill the field 'conversation_report_gpt' but it's not filling anything. I also tried other things such as $this->data['conversation_report_gpt'] = $something and $set() but none of them works for me. This action resides in a Create page of resource
3 replies
FFilament
Created by Patrick on 3/1/2024 in #❓┊help
get a field value in an action
How can i get the value of a form field inside an action? This is my action: Actions\Action::make('gespreksverslag_herschrijven') ->label('Gespreksverslag herschrijven') ->icon('heroicon-o-pencil') ->action(function(Get $get){ $originalText = $get('conversation_report_original');
$service = new RewriteTextWithGPTService(); $rewrittenText = $service->handle(static::$prompt, $originalText); $this->form->fill(['conversation_report_gpt' => $rewrittenText]); }),
$get() will give m the following error: Typed property Filament\Forms\Components\Component::$container must not be accessed before initialization It must be simple, but I can't find it in the docs. What am i missing?
13 replies
FFilament
Created by Patrick on 2/22/2024 in #❓┊help
How to set a form value in a resource from a custom action
I have an action that contains a conversation_report_gpt textarea, I would like to update the value of this field after clicking on an action button.
7 replies
FFilament
Created by Patrick on 2/19/2024 in #❓┊help
How to implement a dynamic form in an action
I would like to display fields based on a database entry. I have this action:
Action::make('Opleiding inplannen')
->form([
Select::make('education_id')
->label('')
->options(Education::orderBy('name', 'asc')->pluck('name', 'id'))
->required()
->live()
->afterStateUpdated(fn (Select $component) => $component
->getContainer()
->getComponent('planningForm')
->getChildComponentContainer()
->fill()
),
Grid::make(2)
->schema(function(Get $get){

$educationId = $get('education_id');

if($educationId){
return Educations::getPlanningFormSchemaArray(
Education::find($educationId)
);
}

return [];
})
->key('planningForm')

])
->action(function(array $data){

})
->slideOver()
->after(function($data){
$url = route('filament.admin.resources.education.edit', ['record' => $data['education_id']]).'?openPlanningForm=true';
return redirect($url);
}),
Action::make('Opleiding inplannen')
->form([
Select::make('education_id')
->label('')
->options(Education::orderBy('name', 'asc')->pluck('name', 'id'))
->required()
->live()
->afterStateUpdated(fn (Select $component) => $component
->getContainer()
->getComponent('planningForm')
->getChildComponentContainer()
->fill()
),
Grid::make(2)
->schema(function(Get $get){

$educationId = $get('education_id');

if($educationId){
return Educations::getPlanningFormSchemaArray(
Education::find($educationId)
);
}

return [];
})
->key('planningForm')

])
->action(function(array $data){

})
->slideOver()
->after(function($data){
$url = route('filament.admin.resources.education.edit', ['record' => $data['education_id']]).'?openPlanningForm=true';
return redirect($url);
}),
Now the
Educations::getPlanningFormSchemaArray
Educations::getPlanningFormSchemaArray
returns an array with a schema However, when i select an education the initial value just gets reset in the select instead of seeing the new form. How can i do this?
7 replies
FFilament
Created by Patrick on 2/15/2024 in #❓┊help
open action when a GET parameter is set
I'd like to open a specific action when a user comes to a page and a specific $_GET parameter is present. It's an edit form of a resource, which contains a header action button. Which has a wireclick:
wire:click="mountAction('Inplannen')"
wire:click="mountAction('Inplannen')"
I would like to automatically open this action when my URL looks like this: /admin/education/1/edit?openPlanningForm=true Is there a way to do this? I was thinking of dispatching something in the mount method , but I don't know what i should dispatch. My edit page:
class EditEducation extends EditRecord
{
protected static string $resource = EducationResource::class;

protected function getHeaderActions(): array
{
return [
Educations::getHeaderPlanAction(),
Actions\DeleteAction::make(),
];
}

public function mount(int|string $record): void
{
parent::mount($record);
if(request()->has('openPlanningForm')){
// do something to open the planning form
}
}
}
class EditEducation extends EditRecord
{
protected static string $resource = EducationResource::class;

protected function getHeaderActions(): array
{
return [
Educations::getHeaderPlanAction(),
Actions\DeleteAction::make(),
];
}

public function mount(int|string $record): void
{
parent::mount($record);
if(request()->has('openPlanningForm')){
// do something to open the planning form
}
}
}
Any tips?
21 replies
FFilament
Created by Patrick on 2/14/2024 in #❓┊help
How to remove the default submit button from a modal
Action::make('Medewerkers bekijken')

->modalContent(fn ($record): View => view(
'filament.resources.course-resource.pages.interests-overview-modal',
['record' => $record],
))
->modalContentFooter(
new HtmlString('')
)
->slideOver()
Action::make('Medewerkers bekijken')

->modalContent(fn ($record): View => view(
'filament.resources.course-resource.pages.interests-overview-modal',
['record' => $record],
))
->modalContentFooter(
new HtmlString('')
)
->slideOver()
Opening a modal with a custom view, this view only displays a table so i dont need a submit button
4 replies
FFilament
Created by Patrick on 2/12/2024 in #❓┊help
custom page throws error when adding trait InteractsWithRecord
I'm not sure what I'm missing. I've created a new custom page with this command:
php artisan make:filament-page RescheduleCourse --resource=CourseResource --type=custom
php artisan make:filament-page RescheduleCourse --resource=CourseResource --type=custom
Added the page to the resource, it displays, all good. Now when I add
use InteractsWithRecord;
use InteractsWithRecord;
trait to it, I get this error:
Declaration of Filament\Actions\Concerns\InteractsWithRecord::getModel(): ?string must be compatible with Filament\Resources\Pages\Page::getModel(): string
Declaration of Filament\Actions\Concerns\InteractsWithRecord::getModel(): ?string must be compatible with Filament\Resources\Pages\Page::getModel(): string
When i remove the ? from the trait for testing, i get the the message that resolveRecord does not exist. This is my page:
<?php

namespace App\Filament\Resources\CourseResource\Pages;

use App\Filament\Resources\CourseResource;
use Filament\Actions\Concerns\InteractsWithRecord;
use Filament\Resources\Pages\Page;

class RescheduleCourse extends Page
{
use InteractsWithRecord;

protected static string $resource = CourseResource::class;

protected static string $view = 'filament.resources.course-resource.pages.reschedule-course';

protected static ?string $title = 'Opleiding opnieuw inplannen';

public function mount(int | string $record): void {
$this->record = $this->resolveRecord($record);
}
}
<?php

namespace App\Filament\Resources\CourseResource\Pages;

use App\Filament\Resources\CourseResource;
use Filament\Actions\Concerns\InteractsWithRecord;
use Filament\Resources\Pages\Page;

class RescheduleCourse extends Page
{
use InteractsWithRecord;

protected static string $resource = CourseResource::class;

protected static string $view = 'filament.resources.course-resource.pages.reschedule-course';

protected static ?string $title = 'Opleiding opnieuw inplannen';

public function mount(int | string $record): void {
$this->record = $this->resolveRecord($record);
}
}
What am i doing wrong?
7 replies
FFilament
Created by Patrick on 2/5/2024 in #❓┊help
show changes with vite
I see i can include a custom stylesheet, but this would require me to build each time i make a change. I'm not sure how to do this. I have a modal with a custom view, and i'd like to use tailwindcss and see the changes directly when Vite is running, but i can only find on how to include a processed css file
11 replies
FFilament
Created by Patrick on 2/2/2024 in #❓┊help
Can't dynamicly show or hide fields in a repeater
I have a form with a select:
Select::make('course')
->label('Cursus/opleiding')
->reactive()
->options(Course::all()->pluck('name', 'id')->toArray())
->required()
Select::make('course')
->label('Cursus/opleiding')
->reactive()
->options(Course::all()->pluck('name', 'id')->toArray())
->required()
Further in the form, i have a Repeater
Repeater::make('schedule')
->label('Planning')
->reactive()
->columns(2)
->schema([
// other fields..
Select::make('course_id')
->label('Cursus')
->reactive()
->options(Course::where('is_bundle', false)->pluck('name', 'id')->toArray())
->visible(function($get){
if($get('course')){
return Course::find($get('course'))->is_bundle;
}

return false;
})->required(),
])
Repeater::make('schedule')
->label('Planning')
->reactive()
->columns(2)
->schema([
// other fields..
Select::make('course_id')
->label('Cursus')
->reactive()
->options(Course::where('is_bundle', false)->pluck('name', 'id')->toArray())
->visible(function($get){
if($get('course')){
return Course::find($get('course'))->is_bundle;
}

return false;
})->required(),
])
Now when i select a course that is a bundle, the course field should be visible, but nothing shows up. When i change the Repeater to a Grid it works just fine, but i need to be able to add multiple entries.
9 replies
FFilament
Created by Patrick on 1/31/2024 in #❓┊help
Calendar plugin will not show events unless we an array
calendar package works great, but it only works when i use an array as event data, when using the EventData class nothing shows up, except when i call toArray() myself
return CourseInstanceSchedule::with('courseInstance')
->whereBetween('start_date', [$fetchInfo['start'], $fetchInfo['end']])
->get()
->map(function($schedule){
return EventData::make()
->id($schedule->id)
->title($schedule->courseInstance->course->name)
->start(
$this->getDateAndTime($schedule->start_date, $schedule->start_time),
)
->end(
$this->getDateAndTime($schedule->start_date, $schedule->end_time)
)
->backgroundColor('red')
->borderColor('red')
->textColor('white')
->toArray();
})->all();
return CourseInstanceSchedule::with('courseInstance')
->whereBetween('start_date', [$fetchInfo['start'], $fetchInfo['end']])
->get()
->map(function($schedule){
return EventData::make()
->id($schedule->id)
->title($schedule->courseInstance->course->name)
->start(
$this->getDateAndTime($schedule->start_date, $schedule->start_time),
)
->end(
$this->getDateAndTime($schedule->start_date, $schedule->end_time)
)
->backgroundColor('red')
->borderColor('red')
->textColor('white')
->toArray();
})->all();
Without the toArray() the calendar stays empty. Not really a big issue, but it shouldn't be nessecary right?
5 replies
FFilament
Created by Patrick on 1/17/2024 in #❓┊help
after callback not fired for EditAction
After submitting the form, I expect to see a dump and die. But it's not being called.
$table ->actions([
Tables\Actions\EditAction::make()
->after(function(){
dd('after');
}),
Tables\Actions\DeleteAction::make(),
])
$table ->actions([
Tables\Actions\EditAction::make()
->after(function(){
dd('after');
}),
Tables\Actions\DeleteAction::make(),
])
It's a table in a relation manager Am i missing something?
5 replies
FFilament
Created by Patrick on 1/12/2024 in #❓┊help
Translate table column value
Can't find it in the docs. I want to display a status badge in table. The name is in english in my database, but i'd like to display the value in Dutch. I'm not sure I can change this. Any suggestions?
Tables\Columns\TextColumn::make('status')
->label('Status')
->badge()
->color(fn(string $state): string => match ($state) {
'accepted' => 'gray',
'finished' => 'success',
'cancelled' => 'warning',
'failed' => 'danger',
})
->sortable(),
Tables\Columns\TextColumn::make('status')
->label('Status')
->badge()
->color(fn(string $state): string => match ($state) {
'accepted' => 'gray',
'finished' => 'success',
'cancelled' => 'warning',
'failed' => 'danger',
})
->sortable(),
6 replies
FFilament
Created by Patrick on 12/12/2023 in #❓┊help
CSV import job is not executed
I've made an importer:
<?php

namespace App\Filament\Imports;

use App\Models\Invitee;
use Filament\Actions\Imports\ImportColumn;
use Filament\Actions\Imports\Importer;
use Filament\Actions\Imports\Models\Import;

class InviteeImporter extends Importer
{
protected static ?string $model = Invitee::class;
// etc
<?php

namespace App\Filament\Imports;

use App\Models\Invitee;
use Filament\Actions\Imports\ImportColumn;
use Filament\Actions\Imports\Importer;
use Filament\Actions\Imports\Models\Import;

class InviteeImporter extends Importer
{
protected static ?string $model = Invitee::class;
// etc
Now i added this import button to a relationmanager (Invitee) When clicking the button, the modal appears, i can map my fields and then i get the noficiation that the Job is running on the background. I have my queue_driver on SYNC, so that it should run directly. After digging a little deeper, i found the trait that dispatches the job and sends the notification to the database.
Starting on line 183
Starting on line 183

$importChunkIterator = new ChunkIterator($csvResults->getRecords(), chunkSize: $action->getChunkSize()); /** @var array<array<array<string, string>>> $importChunks */ $importChunks = $importChunkIterator->get(); $job = $action->getJob(); $options = array_merge( $action->getOptions(), Arr::except($data, ['file', 'columnMap']), ); $importJobs = collect($importChunks) ->map(fn (array $importChunk): object => new ($job)( $import, rows: $importChunk, columnMap: $data['columnMap'], options: $options, )); Bus::batch($importJobs->all())
```$importJob->all()
```$importJob->all()
is always empty for some reason. The imports table in the database recieves the records, they are there. I'm not sure where to look now. Any idea's?
26 replies