Laravel - Passing array of data to view and accessing array elements conditionally

时间:2018-12-03 13:06:14

标签: laravel email-integration

Suppose I design an email template notifying about the interview scheduled for 3 candidates to a recruiter, so in that case I send candidates array of 3 elements as a variable to my template. How do I access individual candidates name in that case?

1 个答案:

答案 0 :(得分:0)

您只需使用

就可以像其他任何参数一样传递参数
$candArr = Candidates::where('something','value')->get();
return view('email')->with('candidates',$candArr);

$candArr = Candidates::where('something','value')->get();
return view('email',compact('candArr'));

然后在视图中

@foreach($candArr as $key)
 {{$key->name}}
@endforeach

希望有帮助!