微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何将变量传递给降价? Laravel 邮件

如何解决如何将变量传递给降价? Laravel 邮件

我正在使用 MailMessage 向 mailtrap 发送邮件消息,并传递了一个变量 email

我的问题是它无法识别我在 Markdown 中传递的变量。它在下面返回错误

Facade\Ignition\Exceptions\ViewException:未定义变量:电子邮件(视图:/var/www/resources/views/ema...

有人知道传递和获取变量 from-to markdown 的正确方法是什么吗?


这是我的代码

return (new MailMessage)
    ->greeting('hello')
    ->line('Innerline sample')
    ->action('Reset Button','http://localhost:3002/reset?sample=gibor213kg')
    ->line('sample')
    ->markdown('emails.reset')
    ->with('email','orange@gmail.com');

这是我的 Markdown 外观

@component('mail::layout',['email' => $emaill])

//more codes here

{{ $email }}

//more codes here

@endcomponent

解决方法

将变量作为第二个参数传递。

import java.util.ArrayList;

public class BestSum {
    ArrayList<Integer> memoInt;
    ArrayList<ArrayList<Integer>> memoList;
    BestSum () {
        memoList = new ArrayList<ArrayList<Integer>>();
        memoInt = new ArrayList<Integer>();
    }
    public ArrayList<Integer> sum (int target,int nums[]) {
        for(int i = 0; i < memoInt.size(); i++) {
            if(memoInt.get(i) == target) {
                return memoList.get(i);
            }
        }
        if(target == 0) {
            return new ArrayList<Integer>();
        }
        if(target < 0) {
            return null;
        }
        ArrayList<Integer> shortestCombination = null;

        for(int i  = 0; i < nums.length; i++) {
            int rest = target-nums[i];
            ArrayList<Integer> currentCombination = sum(rest,nums);
            if(currentCombination != null) {
                currentCombination.add(nums[i]);
                if(shortestCombination == null || currentCombination.size() < shortestCombination.size()){
                    shortestCombination = new ArrayList<Integer>();
                    shortestCombination = (ArrayList)currentCombination.clone();
                }
            }
        }
        memoInt.add(target);
        memoList.add(shortestCombination);
        return shortestCombination;
    }
    public static void main(String[] args) {
        int target = 8;
        int nums[] = {1,4,5};
        BestSum bs = new BestSum();
        System.out.println(bs.sum(target,nums).toString()); //[4,4]
    }
}

https://laravel.com/docs/8.x/mail#markdown-mailables

,

我最终通过使用 compact 而不是数组得到了解决方案。我更改了下面的这一行,一切正常。

->markdown('emails.reset',compact('email'))

来自laracasts 的@sibongisenimsomis 信用

显然,将变量从 Notification 类传递给 Markdown 的工作方式有所不同。我在我的解决方案中使用了紧凑型,经过大约一个小时的努力,因为我指的是另一个在 Mailable 类上使用 with 的例子。

https://laracasts.com/discuss/channels/laravel/passe-some-variables-to-the-markdown-template-within-a-notification

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。