亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用 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 關注
  • 163 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號