php – 包含在每个foreach循环迭代中重复的刀片模板
发布时间:2020-12-13 16:56:11 所属栏目:PHP教程 来源:网络整理
导读:我正在使用Blade模板与Laravel,我正在尝试使用@foreach循环来显示通知.问题是,如果我说了10个通知,则第一个通知重复10次. 输出每个通知的代码: @foreach ( Auth::user()-unreadNotifications as $notification ) {{ $notification-type-web_template }} {{
我正在使用Blade模板与Laravel,我正在尝试使用@foreach循环来显示通知.问题是,如果我说了10个通知,则第一个通知重复10次.
输出每个通知的代码: @foreach ( Auth::user()->unreadNotifications as $notification ) {{ $notification->type->web_template }} {{ $notification->id }} @include($notification->type->web_template) @endforeach web_template将输出模板的路径:notifications.web.user_alert 对于循环的每次迭代,{{$notification-> type-> web_template}}和{{$notification-> id}}将输出他们应该的内容,但@include($notification-> type – > web_template)每次只输出第一个通知. 所以输出看起来像: 156 notification.web.new_message 你有来自Joe的新消息. 154 notification.web.user_alert 你有来自Joe的新消息. 145 notification.web.new_like 你有来自Joe的新消息. 我认为这可能是某种缓存问题,但我找不到任何有同样问题的人. 有任何想法吗? 更新:添加一些代码 示例通知视图: @extends('layouts.notification-wrapper') @section('url',url('jobs/'.$notification->job_id.'#highlight'.$notification->bid_id)) @section('image','/assets/img/no-photo.jpg') @section('header',$notification->collector->firstname . ' ' . $notification->collector->secondname) @section('description') has placed a bid of |