You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Laravel Filament Ticketing:如何将$recipients设为选中的指派用户

解决方法

你的assigned_to_id是单选选择器,存储的是选中用户的ID,直接从创建后的工单记录中获取该ID,再通过插件配置的用户模型找到对应用户实例即可替换$recipients变量:

修改后的通知代码

$record = $this->record;

// 获取插件配置的用户模型类
$userModel = config('filament-ticketing.user-model');
// 从工单记录中读取选中的指派用户ID,查询对应的用户实例
$recipient = $userModel::find($record->assigned_to_id);

// 仅当选中用户时发送通知,避免空对象报错
if ($recipient) {
    $recipient->notify(
        Notification::make()
            ->title('New Incident Created')
            ->icon('heroicon-o-document-text')
            ->body(
                "**New incident: " .
                    __($record->ir_number->prefix ?? 'IR#' . str_pad($record->ir_number, 4, '0', STR_PAD_LEFT)) .
                    " of type {$record->caseTypeRelationship->name} was created by " . auth()->user()->name . "**"
            )
            ->actions([
                Action::make('View')
                    ->url(TicketResource::getUrl('view', ['record' => $record])),
            ])
            ->toDatabase(),
    );
}

关键说明

  1. 用config('filament-ticketing.user-model')获取插件配置的用户模型,避免硬编码User类,贴合插件设计规范
  2. $record->assigned_to_id直接读取选择器提交的用户ID,Filament会自动将表单字段值保存到记录中
  3. 增加if ($recipient)判断,防止未选中用户时触发空对象错误

如果后续需要改成多选指派用户,只需给Select组件添加multiple(),再修改代码为:

$userModel = config('filament-ticketing.user-model');
$recipients = $userModel::whereIn('id', $record->assigned_to_id)->get();

foreach ($recipients as $recipient) {
    // 原通知逻辑保持不变
}

内容的提问来源于stack exchange,提问作者Abdulrahman Mushref

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.28 23:40:38