shaan
shaan
Explore posts from servers
FFilament
Created by shaan on 11/20/2024 in #❓┊help
Tooltips not working on Disabled Action Button.
Here is the implementation
DirectPrintAction::make()
->visible(fn ($record) => $record->payment_status !== PaymentStatus::PENDING)
->disabled(function () {
$defaultPrinter = Printer::where('is_default', true)->first();

return ! $defaultPrinter || $defaultPrinter->status === PrinterStatus::OFFLINE;
})
->tooltip(function () {
$defaultPrinter = Printer::where('is_default', true)->first();
if (! $defaultPrinter) {
return 'No default printer set';
}

return $defaultPrinter->status === PrinterStatus::OFFLINE ? 'Please check printer status' : '';
})
->icon('heroicon-o-printer'),
DirectPrintAction::make()
->visible(fn ($record) => $record->payment_status !== PaymentStatus::PENDING)
->disabled(function () {
$defaultPrinter = Printer::where('is_default', true)->first();

return ! $defaultPrinter || $defaultPrinter->status === PrinterStatus::OFFLINE;
})
->tooltip(function () {
$defaultPrinter = Printer::where('is_default', true)->first();
if (! $defaultPrinter) {
return 'No default printer set';
}

return $defaultPrinter->status === PrinterStatus::OFFLINE ? 'Please check printer status' : '';
})
->icon('heroicon-o-printer'),
1 replies
FFilament
Created by shaan on 7/15/2024 in #❓┊help
Filamentphp Repeaters
php Repeater::make('items')
->relationship('items')
->schema([
Select::make('stock_id')
->label('Product')
->searchable()
// ->options(Stock::pluck('product_name', 'id'))
->options(function () {
return Stock::get()->mapWithKeys(fn($product
) => [$product->id => "{$product->product_name} (Available: {$product->quantity})"]);
})
->required()
->reactive(),
TextInput::make('quantity_requested')
->numeric()
->required(),
TextInput::make('quantity_issued')
->numeric()
->required()
->reactive()
->visible(),
])
->columns(3),
php Repeater::make('items')
->relationship('items')
->schema([
Select::make('stock_id')
->label('Product')
->searchable()
// ->options(Stock::pluck('product_name', 'id'))
->options(function () {
return Stock::get()->mapWithKeys(fn($product
) => [$product->id => "{$product->product_name} (Available: {$product->quantity})"]);
})
->required()
->reactive(),
TextInput::make('quantity_requested')
->numeric()
->required(),
TextInput::make('quantity_issued')
->numeric()
->required()
->reactive()
->visible(),
])
->columns(3),
this is my repeater, this is stockrequest_table, so i want to deduct quantity_issued from stock tables quantity and overwrite it. Have tried alot. is it possible with json?
3 replies
FFilament
Created by shaan on 7/1/2024 in #❓┊help
Slow Query - Slow Endpoints in Filamentphp v3
No description
7 replies
FFilament
Created by shaan on 6/25/2024 in #❓┊help
Pdf generation and sending Database notifications takes too much time.
Pdf generation and sending Database notifications takes too much time. like 5 to 6s. I have created a Job too. still its taking same amount of time. Here is my code for Job
php class ProcessLetterApproval implements ShouldQueue
{

protected $letter;

protected $userId;

public function __construct(Letter $letter, $userId)
{
$this->letter = $letter;
$this->userId = $userId;
}

public function handle()
{
$this->letter->update([
'status' => 'approved',
]);

$pdf = PDF::loadView('letter-template', ['letter' => $this->letter]);

$fileName = 'letter_'.$this->letter->id.'_'.time().'.pdf';

Storage::put('public/letters/'.$fileName, $pdf->output());


$this->letter->update(['file_path' => 'letters/'.$fileName]);
}

protected function sendNotification()
{
$recipient = User::find($this->letter->user_id);

Notification::make()
->body("Your {$this->letter->template->name} Letter Request has been changed")
->actions([
Action::make('index')
->url(LetterResource::getUrl('index',
['record' => $this->letter])),
])
->sendToDatabase($recipient);
}
}
php class ProcessLetterApproval implements ShouldQueue
{

protected $letter;

protected $userId;

public function __construct(Letter $letter, $userId)
{
$this->letter = $letter;
$this->userId = $userId;
}

public function handle()
{
$this->letter->update([
'status' => 'approved',
]);

$pdf = PDF::loadView('letter-template', ['letter' => $this->letter]);

$fileName = 'letter_'.$this->letter->id.'_'.time().'.pdf';

Storage::put('public/letters/'.$fileName, $pdf->output());


$this->letter->update(['file_path' => 'letters/'.$fileName]);
}

protected function sendNotification()
{
$recipient = User::find($this->letter->user_id);

Notification::make()
->body("Your {$this->letter->template->name} Letter Request has been changed")
->actions([
Action::make('index')
->url(LetterResource::getUrl('index',
['record' => $this->letter])),
])
->sendToDatabase($recipient);
}
}
And Here is the LetterEdit
php protected function getHeaderActions(): array
{
return [
Action::make('approve')
->action(function (Letter $record) {
$this->record->update([
'status' => 'approved',
'approved_at' => now(),
'approved_by' => auth()->user()->id,
]);
ProcessLetterApproval::dispatch($record, auth()->id());
$this->redirect(static::getResource()::getUrl('index'));
})
];
}
php protected function getHeaderActions(): array
{
return [
Action::make('approve')
->action(function (Letter $record) {
$this->record->update([
'status' => 'approved',
'approved_at' => now(),
'approved_by' => auth()->user()->id,
]);
ProcessLetterApproval::dispatch($record, auth()->id());
$this->redirect(static::getResource()::getUrl('index'));
})
];
}
16 replies
FFilament
Created by shaan on 6/20/2024 in #❓┊help
Issues with Assigning multiple roles
php Forms\Components\Select::make('roles')
->inlineLabel()
->searchable()
->multiple()
->visible(fn () => auth()->user()->can('approveAny', User::class))
->options(Role::all()->pluck('description', 'id')->toArray())
->afterStateHydrated(fn ($set, $record) => $set('roles',
$record?->roles->pluck('id')->toArray()))
->preload(),
php Forms\Components\Select::make('roles')
->inlineLabel()
->searchable()
->multiple()
->visible(fn () => auth()->user()->can('approveAny', User::class))
->options(Role::all()->pluck('description', 'id')->toArray())
->afterStateHydrated(fn ($set, $record) => $set('roles',
$record?->roles->pluck('id')->toArray()))
->preload(),
this is the code in UserResource, and
php private function assignRole(User $user, UserData $user_data): void
{
$has_permission = auth()->user()->can('approveAny', User::class);
if ($has_permission && $user_data->role) {
$user->assignRole($user_data->role);
return;
}

$this->revertToGuestRole($user);
}

private function revertToGuestRole(User $user): void
{
$guest_role = config('defaults.guest_role_id') ?: -1;
$guest_role = Role::find($guest_role);

if ($guest_role) {
$user->roles()->sync([$guest_role]);
}
}
php private function assignRole(User $user, UserData $user_data): void
{
$has_permission = auth()->user()->can('approveAny', User::class);
if ($has_permission && $user_data->role) {
$user->assignRole($user_data->role);
return;
}

$this->revertToGuestRole($user);
}

private function revertToGuestRole(User $user): void
{
$guest_role = config('defaults.guest_role_id') ?: -1;
$guest_role = Role::find($guest_role);

if ($guest_role) {
$user->roles()->sync([$guest_role]);
}
}
these are methods in UserServices, that i use to assign. However, i could not track the issue. This is the error it give while i try to save after selecting multiple roles. trying to implement multiple() https://flareapp.io/share/LPdv3Mg5
1 replies
FFilament
Created by shaan on 6/17/2024 in #❓┊help
Editor js or full featured editor for filament
Is there any? which one is the best?
4 replies
FFilament
Created by shaan on 6/7/2024 in #❓┊help
is there any titleCase() for filament tables?
to display the table values in title case
6 replies