doushi4956 2017-02-04 18:29
浏览 155
已采纳

Laravel,从刀片模板文件调用控制器方法

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!

  • 写回答

2条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 在matlab中如何进行三个参数的离散傅里叶逆变换(idft)
      • ¥15 遇到问题了,求解答!
      • ¥15 请问coppliasim eduUR5视觉抓取怎么实现仿真,
      • ¥30 JavaWeb实验(购物平台)
      • ¥15 八路抢答器倒计时设计时显示器不输出,只能显示0
      • ¥15 用C语言随机生成一个迷宫
      • ¥15 超多因素的正交方案设计
      • ¥15 Scratch~汽车小游戏
      • ¥30 OSGB转换为3dtiles
      • ¥25 用于Audio的芯片中“Audio Interface”和“Mode Control”是什么?