【发布时间】:2020-02-13 19:07:52
【问题描述】:
通过控制器方法,我将$notifications 发送到主视图并在我的网站标题上显示通知。
个人资料视图扩展了主页视图,我还想在个人资料视图上显示通知。
但是当我请求配置文件视图时,它会生成一个未定义变量 $notifications 的错误。
我认为一种解决方案是在从控制器方法返回配置文件视图时发送$notifications,但是在网站上,我想在很多视图上显示通知选项卡,所以这是我想的正确方式。
我通过以下方式返回主页视图
return view('home')->with(['unseen_notification_counter'=>$unseen_notification_counter,'notifications'=>$notifications]);
这是标题部分的主页视图中的代码
<ul class="dropdown-menu" id="notificationlist">
@foreach($notifications as $notification)
<li>
<a href="{{route('user.profile',$notification->id)}}" class="dropdown-item">
<img src="http://localhost/webproject/public/user_images/{{$notification->image}}" class="img-thumbnil" width="20px" height="20px">
<strong>{{$notification->username}}</strong>
<span style="white-space: initial;">sent you a friend request.</span>
</a>
</li>
@endforeach
</ul>
【问题讨论】:
-
你如何将通知传递给视图?
-
你能说明你在哪里扩展你的视野吗?
-
你能说明你是如何获得通知的吗(抱歉)?
标签: php laravel laravel-5 laravel-5.2