如何调试" ErrorException未定义的变量"?

时间:2018-05-21 18:23:04

标签: php html laravel

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

  

ErrorException未定义的变量:invitationsN(查看:C:\ xampp \ htdocs \ netPol \ resources \ views \ layouts \ complainant.blade.php)(查看:C:\ xampp \ htdocs \ netPol \ resources \ views \ layouts \ complainant.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 ]);
}

}

2 个答案:

答案 0 :(得分:0)

你好朋友可以使用

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

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

use Illuminate\Support\Facades\Log;

你只需要做一个尝试捕捉,然后在catch类型中输入 Log 静态方法。

答案 1 :(得分:0)

更新您的代码

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

  return View('invitationsN');
}