【问题标题】:How to debug "ErrorException Undefined variable"?如何调试“ErrorException 未定义变量”?
【发布时间】:2023-03-07 10:51:01
【问题描述】:

当我尝试在浏览器中运行我的应用程序时,我不断收到此错误。它适用于 Laravel 5.3 但不适用于 5.5

ErrorException 未定义变量:invitationsN(查看:C:\xampp\htdocs\netPol\resources\views\layouts\complainant.blade.php)(查看:C:\xampp\htdocs\netPol\resources\views\layouts\投诉者.blade.php

查看

<i class="entypo-list"></i> <span
        class="badge badge-warning">{{sizeof($invitationsN)}}</span> </a>
<ul class="dropdown-menu">
<!-- TS14950193223600: Xenon - Boostrap Admin Template created by Laborator / Please buy this theme and support the updates -->
<li class="top"><p>You have {{sizeof($invitationsN)}} invitation(s)</p></li>
<li>
    <ul class="dropdown-menu-list scroller">
        @forelse($invitationsN as $invitation)

            <li class="unread notification-success">
                <a href="{{url('report/'.$invitation->report->code."/?invitation=1")}}">
                    <i class="entypo-eye pull-right"></i>
                    <span class="line">
                        <strong><b>From: </b>{{$invitation->invitor->name}}</strong>
                    </span>
                    <span class="line small">
                        {{\Carbon\Carbon::parse($invitation->created_at)->diffForHumans()}}
                    </span>
                </a>
            </li>

        @empty
        @endforelse

    </ul>
</li>

代码

use Net_Police\User;
use Illuminate\Support\Facades\Auth;
use Illuminate\View\View;

class NotificationComposer
{
public $user;
public function __construct()
{
// $this->user = $user;
 }

public function compose(View $view)
{
    if(Auth::guest()){
        $invitationsN = [];
    }else{
        $invitationsN = Auth::user()->receivedInvitations;
    }

    $view->with([ 'invitationsN' => $invitationsN ]);
}

}

【问题讨论】:

  • 试一试,但删除with()中的数组括号
  • 确保您在服务提供商中注册了您的视图编辑器。
  • @Daniel 非常感谢。有效。我创建了一个未注册的 ComposerServiceProvider。这就是问题的根源。

标签: php html laravel


【解决方案1】:

更新你的代码

public function compose(View $view)
{
  if(Auth::guest()){
      $invitationsN = [];
  }else{
      $invitationsN = Auth::user()->receivedInvitations;
  }

  return View('invitationsN');
}

【讨论】:

    【解决方案2】:

    你好朋友你可以使用

    Log::debug('An informational message.');
    

    你也会发现她的不同层次:

    use Illuminate\Support\Facades\Log;
    

    您只需要进行 try and catch 并在 catch 中键入 Log 静态方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-05
      • 2018-01-26
      • 2020-09-24
      • 2018-11-29
      • 2020-04-16
      相关资源
      最近更新 更多