Heey伙计们! 我使用Laravel 5.4,WAMP for localhost。 我正在努力解决这个问题,在我的 我应该在头文件中收到所有这些数据。 我用过: {{App :: make(“NotificationController”) - > getNotification()}} strong>
和 {{NotificationController :: getNotification()}} strong>但是 它说 header.blade.php code>文件中调用
Controller @ methodName code>,因为我想在我的header.blade.php文件中显示所有通知 对于用户。 通常我在不同页面的路线的帮助下获得所有需要的数据。 但是对于这种情况,我需要不使用路由来打电话。 这是我的
NotificationController code>的代码: p>
类NotificationController extends Controller
{
public function getNotification(){
$ notifications = Notification :: where('user_id',Auth :: user() - > id) - > get();
$ unread = 0;
foreach($ notifications as $ notify){
if( $ notify-> seen == 0)$ unread ++;
}
return ['notifications'=> $ notifications,'unread'=> $ unread];
}
}
< / code> pre>
Class NotificationController不存在 code>。 请注意! p>
div>
Heey guys! I use Laravel 5.4, WAMP for localhost. I am struggling with the problem to call a Controller@methodName
within my header.blade.php
file, because I want to show in my header.blade.php file all notifications for the User. Normally I was getting all needed data with the help of routes in different pages. But for this case I need to call without using routes. Here is my code for my NotificationController
:
class NotificationController extends Controller
{
public function getNotification(){
$notifications = Notification::where('user_id',Auth::user()->id)->get();
$unread=0;
foreach($notifications as $notify){
if($notify->seen==0)$unread++;
}
return ['notifications'=>$notifications, 'unread'=>$unread];
}
}
And I should receive all these data in my header file. I have used: {{App::make("NotificationController")->getNotification()}}
and {{NotificationController::getNotification() }} But it says Class NotificationController does not exist
. Please heelp!