使用 Laravel Nova Actions 发送电子邮件

我想通过 Laravel Nova 上的按钮发送一封带有操作的邮件(我认为这是最合适的)。我已经有一个保存在可邮寄文件中的邮件模板,我已经创建了我的资源,但我不知道要放入什么内容,因为我需要从该资源中检索信息,例如名称、价格或发送日期行已创建(在与我的资源相关的表中)。


我的资源代码:


<?php


namespace 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

     */



潇湘沐
浏览 143回答 1
1回答

神不在的星期二

&nbsp; // in EmailOrderConfirmation --nova action&nbsp; // declare what you are using&nbsp; // use Illuminate\Support\Facades\Mail;&nbsp; // use App\Mail\ResendOrder;&nbsp;&nbsp;&nbsp; public function handle(ActionFields $fields, Collection $models)&nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; //loop over the orders that have been selected in nova&nbsp; &nbsp; &nbsp; &nbsp; foreach ($models as $order) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $contact = $order->contract; //however you are getting contract data&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //assuming you have a $order->user&nbsp; order belongs to user relationship&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //send mail to the user, with the order/contract details to create your email&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Mail::to($order->user->email)->send(new ResendOrder($contact));&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; //return a message to nova&nbsp; &nbsp; &nbsp; &nbsp; return Action::message('Mail envoyé');&nbsp; &nbsp; }&nbsp; &nbsp; // in&nbsp; Order /Nova resource&nbsp; &nbsp; // declare what you are using&nbsp; &nbsp; // use App\Nova\Actions\EmailOrderConfirmation;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; public function actions(Request $request)&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; return [new EmailOrderConfirmation];&nbsp; &nbsp; }
打开App,查看更多内容
随时随地看视频慕课网APP