Laravel检索可邮寄的视图名称

时间:2018-11-26 19:02:48

标签: laravel laravel-5 laravel-mail

我正在尝试检索视图 markdown 名称(未呈现视图)之类的数据示例:{{1} } 用于emails.user.welcome目录中的每个可邮递类。

各种转储app/Mail可邮寄类:

UserWelcome

Var dump输出

Route::get('rendermail', function() {

     $email = ( new App\Mail\UserWelcome() );

     return dd($email);

});

1 个答案:

答案 0 :(得分:0)

routes / web.php

$return = [];
$files = scandir("./Mail");
foreach ($files as $key => $value) {
    $fullFileName = explode(".", $value);
    if ($fullFileName[1] === "php") {
        $fileName = $fullFileName[0];
        $className = "App\Mail\". $fileName ."()";

        array_push($return, (new $className)->returnArray());
    }
}
return $return;

在所有MailableClasses中添加returnArray方法

<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;

class testMail extends Mailable
{
    use Queueable, SerializesModels;

    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->form = "Test";
        $this->view = "home";
        $this->subject = "home";
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function returnArray()
    {
        return [$this->view];
    }
}