【问题标题】:Undefined variable: error in Laravel 5.6未定义的变量:Laravel 5.6 中的错误
【发布时间】:2018-12-18 23:17:43
【问题描述】:

我有控制器将数据输入数据库并在重复数据时显示错误但我收到消息

未定义变量:错误

$cek = DB::table('peserta')->where('email',$email)->count();
  if ($cek > 0 and count($error) > 0 ) {
    $pesan = [];
    $pesan['halu'] = 'danger';
    $pesan['message'] = 'Email anda sudah terdaftar';
  }

【问题讨论】:

  • $error 来自哪里?
  • @tkausl 如果重复数据得到消息错误
  • 你没有声明你想要$error 是什么。

标签: laravel laravel-5


【解决方案1】:

您的变量 $error 未定义。意思是,在您的代码中的某处,变量$error 未分配给任何值,请检查count($error) 附近的第2 行。

【讨论】:

    【解决方案2】:

    变量$error 未定义。因为你使用了$error,但是之前没有声明$errorif ($cek > 0 and count($error) > 0 )” 这条线。而这个 $error 需要数组类型的数据。因为,count() 需要数组类型的数据。

    我认为您的代码如下:

    $cek = DB::table('peserta')->where('email',$email)->count();
    $error = your own errors array;
      if ($cek > 0 and count($error) > 0 ) {
        $pesan = [];
        $pesan['halu'] = 'danger';
        $pesan['message'] = 'Email anda sudah terdaftar';
      }
    

    【讨论】:

      猜你喜欢
      • 2020-02-22
      • 1970-01-01
      • 2019-01-19
      • 2016-03-30
      • 1970-01-01
      • 1970-01-01
      • 2016-04-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多