如何传递与 vue 模板相关的 Eloquent 数据

How to pass Eloquent data with relation to vue template

我正在尝试将模型关系从 blade 传递到 vue.js 模板。

我有 2 个模型有关系,很快:

class Emails extends Model
{
   public function template()
   {
       return $this->belongsTo(Template::class);
   }
}

和另一个有 has many 关系。

有了这样的请求 $mails = Emails::all(); 我可以在 foreach 之后使用 blade 访问模板,例如 $mail->template

但是如果我将它传递给 vue.js 模板 <sometemplate :mails="{{$mails}}",在 foreach 之后 mail.template 将是空的。

我知道,我做错了什么,但找不到解决方案。

抱歉,已找到我的解决方案。我必须添加 with('template') to my request