【问题标题】:Use of undefined constant Yes - assumed 'Yes' laravel使用未定义的常量是 - 假设是'是' laravel
【发布时间】:2017-10-31 15:44:37
【问题描述】:

我似乎不断收到此错误“Use of undefined constant Yes - assumed 'Yes'”,我不知道为什么?我在网上看了一圈,还是不明白。有人说这是引导错误或其他原因。谁能帮帮我,非常感谢

Home.blade.php

 <table class="table table-bordered">
      <tr>
        <th><strong><big>Name: </big></strong></th>     
        <th><strong><big>Approval Status: </big></strong></th>  
      </tr>
      <td>
      <tr>
        @foreach($data as $value)
      <tr>    
      <th><a href="{{route('user.show',['id'=>$value->id])}}">{{$value->Name}}</a></th>
    <th> 
      @foreach($data1 as $value1)

      {{$value1->approval_status}}

   </th>              
      </tr>
      @endforeach
         @endforeach
      </tr>
      </tr>
    </table>

家庭控制器:

public function getData(){
        $data['data'] = DB::table('user_infos')->where('deleted_at',NULL)->get()->sortByDesc('created_at');

        if(count($data)>0){
        return view('home',$data);
    }else{
    return view('home');
}

        public function approval_view(){
    $data1 = DB::table('approvals')->where('approval_status',Yes)->get();
    return view('home',compact('data1'));
    }

【问题讨论】:

  • where('approval_status','Yes') 错过了是的报价

标签: php laravel


【解决方案1】:

您忘记将“是”用引号括起来。

更改:where('approval_status',Yes)

收件人:where('approval_status','Yes')

PHP 认为它是一个常量,这里不是这样。

【讨论】:

  • 天哪,你是对的,不能相信这个小错误,我之前使用了 where 子句,它似乎不是引用,所以我认为不需要它。非常感谢
  • 只是检查我的 $data 有什么问题,因为我得到一个未定义的变量:上次没有错误或任何东西时的数据
  • 因为你返回return view('home');没有变量 data 当计数为 0 时(你的 else 语句)。
【解决方案2】:

这本身不是错误,而是通知。它只是将你的“是”转换为一个字符串,只是让你知道它做了什么。

要解决这个问题,只需将 $data1 = DB::table('approvals')-&gt;where('approval_status',Yes)-&gt;get(); 更改为 $data1 = DB::table('approvals')-&gt;where('approval_status','Yes')-&gt;get();

【讨论】:

  • 只是检查我的 $data 有什么问题,因为我得到一个未定义的变量:上次没有错误或任何东西时的数据
猜你喜欢
  • 1970-01-01
  • 2016-06-23
  • 1970-01-01
  • 2019-09-30
  • 2021-09-23
  • 2014-05-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多