headbanger
headbanger
FFilament
Created by headbanger on 2/9/2024 in #❓┊help
listener not working via echo
I've a custom page in filament whose view is here:
<x-filament-panels::page>
{{ $record->name }}

@foreach ($record->unAnsweredChatSessions as $chatSession)
<a href="#" wire:click="fetchMessages({{ $chatSession->id }})">
{{ $chatSession->oldestMessage->message }}
</a>
<br />
@endforeach

@if ($selectChatSessionId > 0)
<div>
<h2>Chat Session with {{ $selectChatSessionId }}</h2>
<div>
@foreach ($selectedSessionMessages->messages as $message)
<div>
{{ $message->message }} <br><br>
</div>
@endforeach
</div>
<input type="text" wire:model="newMessage" />
<input type="submit" wire:click="sendMessage" />
</div>
@endif
</x-filament-panels::page>
@script
<script type="module">
Echo.private(`new-chat-for-{{ $selectChatSessionId }}`)
.listen('adminchatnotification', (e) => {
$wire.$refresh()
});
</script>
@endscript
<x-filament-panels::page>
{{ $record->name }}

@foreach ($record->unAnsweredChatSessions as $chatSession)
<a href="#" wire:click="fetchMessages({{ $chatSession->id }})">
{{ $chatSession->oldestMessage->message }}
</a>
<br />
@endforeach

@if ($selectChatSessionId > 0)
<div>
<h2>Chat Session with {{ $selectChatSessionId }}</h2>
<div>
@foreach ($selectedSessionMessages->messages as $message)
<div>
{{ $message->message }} <br><br>
</div>
@endforeach
</div>
<input type="text" wire:model="newMessage" />
<input type="submit" wire:click="sendMessage" />
</div>
@endif
</x-filament-panels::page>
@script
<script type="module">
Echo.private(`new-chat-for-{{ $selectChatSessionId }}`)
.listen('adminchatnotification', (e) => {
$wire.$refresh()
});
</script>
@endscript
I am successfully able to dispatch an event CustomerAskedQuestion using laravel event. But I am not able to listen to it in this above mentioned filament custom page view file, neither in the class file like below:
public function getListeners()
{
return [
"echo:adminchatnotification,.new-chat-for-{$this->selectChatSessionId}" => 'fetchMessages',
];
}

public function fetchMessages($selectChatSessionId)
{
dd('event captured');
}
public function getListeners()
{
return [
"echo:adminchatnotification,.new-chat-for-{$this->selectChatSessionId}" => 'fetchMessages',
];
}

public function fetchMessages($selectChatSessionId)
{
dd('event captured');
}
I get Laravel Echo not found error, not sure what should I do to mitigate this error? Noob question I believe?
3 replies
FFilament
Created by headbanger on 2/8/2024 in #❓┊help
form field not resetting + update data
public function table(Table $table): Table
{
return $table
->columns([
TextColumn::make('question'),
])
->actions([
Action::make('Reply')
->form([
TextInput::make('replyMessage')
->required()
->live()
])
->modalContent(function (ChatSession $record, Action $action) {
return view(
'filament.chat-messages.chats',
['chatSession' => $record],
);
})

->extraModalFooterActions(fn(Action $action): array => [
$action->makeModalSubmitAction('Reply', arguments: ['halt' => true]),
])
->action(function ($action, ChatSession $record, array $data, $arguments, Set $set, Get $get) {
$chatMessageService = new ChatMessageService();
$chatMessageService->create($record->id,$data['replyMessage'],auth()->user()->id,true);

if ($arguments['halt'] === true) {
$action->halt();
}
})
->slideOver()
->modalSubmitAction(false)
]);
}
public function table(Table $table): Table
{
return $table
->columns([
TextColumn::make('question'),
])
->actions([
Action::make('Reply')
->form([
TextInput::make('replyMessage')
->required()
->live()
])
->modalContent(function (ChatSession $record, Action $action) {
return view(
'filament.chat-messages.chats',
['chatSession' => $record],
);
})

->extraModalFooterActions(fn(Action $action): array => [
$action->makeModalSubmitAction('Reply', arguments: ['halt' => true]),
])
->action(function ($action, ChatSession $record, array $data, $arguments, Set $set, Get $get) {
$chatMessageService = new ChatMessageService();
$chatMessageService->create($record->id,$data['replyMessage'],auth()->user()->id,true);

if ($arguments['halt'] === true) {
$action->halt();
}
})
->slideOver()
->modalSubmitAction(false)
]);
}
1. How can I reset the value of replyMessage field? $set , $this->form->fill(); $this->reset('replyMessage') - all 3 are not working when written above halt() and anything written after halt doesnt get executed. 2. This custom view (filament.chat-messages.chats), loads the chat message of a user & admin. I am dispatching an event from livewire from the frontend, how can I listen to that event of a new message so that the messages get updated in this modal?
1 replies
FFilament
Created by headbanger on 2/8/2024 in #❓┊help
Filament event listener?
I have a frontend which dispatches an event. I want to be able to listen to that event inside filament and if the user has opened a specific modal then the data inside that modal should be updated using laravel echo. Can I achieve this? I can't find a way to even begin with this, where should I begin looking?
1 replies
FFilament
Created by headbanger on 1/25/2024 in #❓┊help
import with belongstomany fields
I have the following fields that the user has to add for the csv upload: - first_name - last_name - email - role - company name I want to updateOrCreate name and email in the users table while I want to attach role and company to the newly created / existing user. I am trying to achieve this with the following:
public function resolveRecord(): ?User
{
$this->extraData = [
'company_name' => $this->data['company_name'],
'role' => $this->data['role'],
];

unset($this->data['company_name']);
unset($this->data['role']);

return User::firstOrNew(
['email' => $this->data['email']],
[
'first_name' => $this->data['first_name'],
'last_name' => $this->data['last_name'],
'email' => $this->data['email']
]
);
}
public function resolveRecord(): ?User
{
$this->extraData = [
'company_name' => $this->data['company_name'],
'role' => $this->data['role'],
];

unset($this->data['company_name']);
unset($this->data['role']);

return User::firstOrNew(
['email' => $this->data['email']],
[
'first_name' => $this->data['first_name'],
'last_name' => $this->data['last_name'],
'email' => $this->data['email']
]
);
}
protected function afterSave(): void
{
$userService = new UserService();
$user = $userService->getUserByEmailId($this->data['email']);

$user->assignRole($this->extraData['role']);
$companyService = new CompanyService();
$company = $companyService->getCompanyByName($this->extraData['company_name']);

$user->companies()->attach($company->id);
}
protected function afterSave(): void
{
$userService = new UserService();
$user = $userService->getUserByEmailId($this->data['email']);

$user->assignRole($this->extraData['role']);
$companyService = new CompanyService();
$company = $companyService->getCompanyByName($this->extraData['company_name']);

$user->companies()->attach($company->id);
}
But the user is not persisting and hence the afterSave is also not working. So all in all, both resolverecord and aftersave, both are not working. What am I doing wrong?
1 replies
FFilament
Created by headbanger on 1/23/2024 in #❓┊help
How to import belongsToMany fields in the filament importer?
public static function getColumns(): array
{
return [
ImportColumn::make('first_name')
->requiredMapping()
->rules(['required', 'max:255'])
->example('John'),
ImportColumn::make('last_name')
->requiredMapping()
->rules(['required', 'max:255'])
->example('Doe'),
ImportColumn::make('email')
->requiredMapping()
->rules(['required', 'email', 'max:255'])
->example('[email protected]'),
// ImportColumn::make('company_name')
// ->relationship('companies', 'name')
// ->rules(['required', 'max:255', 'exists:mvl_companies,name'])
// ->example('Best Cycles Inc.'),
// ImportColumn::make('company_employee_id')
// ->rules(['required', 'max:255'])
// ->example('BCI-123'),
// ImportColumn::make('company_employee_budget')
// ->numeric()
// ->rules(['required'])
// ->example('10.00,23')
];
}
public static function getColumns(): array
{
return [
ImportColumn::make('first_name')
->requiredMapping()
->rules(['required', 'max:255'])
->example('John'),
ImportColumn::make('last_name')
->requiredMapping()
->rules(['required', 'max:255'])
->example('Doe'),
ImportColumn::make('email')
->requiredMapping()
->rules(['required', 'email', 'max:255'])
->example('[email protected]'),
// ImportColumn::make('company_name')
// ->relationship('companies', 'name')
// ->rules(['required', 'max:255', 'exists:mvl_companies,name'])
// ->example('Best Cycles Inc.'),
// ImportColumn::make('company_employee_id')
// ->rules(['required', 'max:255'])
// ->example('BCI-123'),
// ImportColumn::make('company_employee_budget')
// ->numeric()
// ->rules(['required'])
// ->example('10.00,23')
];
}
public function resolveRecord(): ?User
{
return User::firstOrNew([
'email' => $this->data['email'],
]);
}
public function resolveRecord(): ?User
{
return User::firstOrNew([
'email' => $this->data['email'],
]);
}
The getColumns() has the 3 users table fields on the top followed by the related user_company (pivot table) fields i.e. company_employee_id and company_employee_budget allong with the company name from the companies table commented out. How to I ensure that I am able to add a user and then find the company by name and attach that company with the newly inserted or updated user?
7 replies
FFilament
Created by headbanger on 1/14/2024 in #❓┊help
Filament: Change default table names for imports
0 I want to use the import records functionality mentioned here: https://filamentphp.com/docs/3.x/panels/resources/creating-records#importing-resource-records Although, I want to prefix the tables used in the import functionality in filament: - job_batches -> mvl_job_batches - notifications -> mvl_notifications - imports -> mvl_imports - failed_import_rows -> mvl_failed_import_rows - Also, the user_id columns in these tables needs to change -> mvl_user_id As of now I've tried everything mentioned here https://laracasts.com/discuss/channels/filament/import-record-change-table-names?page=1&replyId=920681 . But I get an error: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'test.imports' doesn't exist What all changes I need to make in order for the import to work successfully.
2 replies
FFilament
Created by headbanger on 1/11/2024 in #❓┊help
Can we get the inserted $record in the afterCreate() when a record is newly added?
The purpose is when a new record gets created, I need to add a default relation record as well. Is there anyway to achieve this?
3 replies