shaan
Explore posts from serversTooltips 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
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),
3 replies
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
And Here is the LetterEdit
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);
}
}
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
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(),
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]);
}
}
1 replies