【问题标题】:Display data of Laravel Notification in laravel blade在 laravel Blade 中显示 Laravel Notification 的数据
【发布时间】:2018-02-04 16:55:18
【问题描述】:

我现在正在实施 laravel 通知。通知存储在通知表中。我试图获取数据列中的数据并在刀片中显示但失败了。

这是我的控制器

public function notification_list(){
    $notifications = auth()->user()->notifications()->orderBy('created_at','desc')->get();

    return view('users.notification.index')->with('notifications',$notifications);
}

这将返回通知集合。但是我无法获取消息等数据。如何提取“数据”并转换为数组?

【问题讨论】:

  • 你的 $notifications 变量打印什么。??
  • 可以使用 toArray() 方法转换为数组。
  • @nikhil_gandhi 是的,它现在工作了,谢谢你的帮助。
  • 我已添加为答案。请接受。

标签: php laravel


【解决方案1】:

您可以使用toArray() 方法将集合转换为数组。

【讨论】:

    【解决方案2】:

    将代码更新到它并运行。

     $notifications = auth()->user()->notifications()->orderBy('created_at','desc')->get()->toArray();
    

    【讨论】:

      【解决方案3】:

      试试这个代码:

      $notifications= DB::table('notifications')->get();
      

      如果您需要加入用户表:

       $notifications= DB::table('notifications')->leftJoin('users', 'notifications.user_id','users.id')->get();
      

      【讨论】:

        【解决方案4】:

        首先,你必须使用顶部的数据库利用数据库;班级 从数据库表中检索数据

            public function notification_list()
            {
        
              $notifications= DB::table('notifications')->all();
        
            return view('users.notification.index' , compact("notifications"));
        
            }
        

        【讨论】:

          猜你喜欢
          • 2021-03-08
          • 2016-10-02
          • 2017-01-05
          • 2021-09-04
          • 1970-01-01
          • 2022-12-10
          • 2018-04-25
          • 1970-01-01
          • 2018-06-04
          相关资源
          最近更新 更多