为了账号安全,请及时绑定邮箱和手机立即绑定

使用 Laravel Nova Actions 发送电子邮件

使用 Laravel Nova Actions 发送电子邮件

PHP
潇湘沐 2023-07-08 15:48:52
我想通过 Laravel Nova 上的按钮发送一封带有操作的邮件(我认为这是最合适的)。我已经有一个保存在可邮寄文件中的邮件模板,我已经创建了我的资源,但我不知道要放入什么内容,因为我需要从该资源中检索信息,例如名称、价格或发送日期行已创建(在与我的资源相关的表中)。我的资源代码:<?phpnamespace App\Nova;use App\Image;use Gloudemans\Shoppingcart\Cart;use Illuminate\Http\Request;use Illuminate\Support\Facades\Auth;use Laravel\Nova\Fields\Currency;use Laravel\Nova\Fields\Date;use Laravel\Nova\Fields\Heading;use Laravel\Nova\Fields\ID;use Laravel\Nova\Fields\Text;use Laravel\Nova\Http\Requests\NovaRequest;use Techouse\IntlDateTime\IntlDateTime;class Order extends Resource{    /**     * The model the resource corresponds to.     *     * @var string     */    public static $model = \App\Order::class;    public static $group = 'Paramètres';    public static function label()    {        return __('Commandes');    }    public static function singularLabel()    {        return __('Commande');    }    /**     * The single value that should be used to represent the resource when being displayed.     *     * @var string     */    public static $title = 'id';    /**     * The columns that should be searched.     *     * @var array     */    public static $search = [        'id',    ];    /**     * Get the fields displayed by the resource.     *     * @param  \Illuminate\Http\Request  $request     * @return array     */
查看完整描述

1 回答

?
神不在的星期二

TA贡献1963条经验 获得超6个赞

  // in EmailOrderConfirmation --nova action

  // declare what you are using

  // use Illuminate\Support\Facades\Mail;

  // use App\Mail\ResendOrder;

  

  public function handle(ActionFields $fields, Collection $models)

  {

        //loop over the orders that have been selected in nova

        foreach ($models as $order) {

            $contact = $order->contract; //however you are getting contract data

            //assuming you have a $order->user  order belongs to user relationship

            //send mail to the user, with the order/contract details to create your email

            Mail::to($order->user->email)->send(new ResendOrder($contact));

        }

        //return a message to nova

        return Action::message('Mail envoyé');

    }


    // in  Order /Nova resource

    // declare what you are using

    // use App\Nova\Actions\EmailOrderConfirmation;

      

    public function actions(Request $request)

    {

        return [new EmailOrderConfirmation];

    }


查看完整回答
反对 回复 2023-07-08
  • 1 回答
  • 0 关注
  • 132 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信