我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

laravel 5.4 count()函数错误

I am using laravel 5.4, there is an error in the code below,
but there is no error when using laravel 5.3,
why is it?

controller:

public function index()
{
    $user=\Auth::user();
    $articles=$user->articles;

    return view('index',  compact('user','articles'));
}

view:

{{ $articles->count() }}

error:

Call to a member function count() on null

what should I do?

Change it to count($articles). ->count() on a null value produces indeed an error.

Laravel 5.4 you should try:

{{ count($articles) }}

近期文章

  • 将带有ajax和jQuery的HTML表单发送到PHP
  • html选中标签更改复选框
  • 在wordpress中更改自定义帖子类型的URL
  • 如何通过url JS传递多个参数
  • 比较数学游戏PHP中的内容
  • 单击后永久禁用/删除按钮
  • 是否可以合并这两个任务计划程序 - Laravel
  • 硬盘启动并且站点崩溃后WordPress错误
  • 如何在打开新标签时保留标签(打开文件)?
  • 为什么我无法在刀片模板中获取CSS资源的完整路径?
  • 如何使用CMIS从Alfresco存储库下载映像?
  • WooCommerce订阅扩展 - 在WooCommerce取消之前取消网关
  • intercom.io与Socialengine 4
  • 从会话用户名派生的外键ID中获取ID和行
  • Yii2 rest API与用户一起发布
  • Mysqli结果Fetch_Row内存泄漏
  • 如果验证成功隐藏提交按钮并显示加载图像
  • 使用外键从第二个表获取值
  • 使用img src属性中的if语句的WordPress特征图像
  • PHP和Classic ASP在同一台机器上返回不同的IP地址

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华