无法雄辩地检索数据

时间:2020-11-03 10:22:08

标签: html mysql laravel eloquent laravel-blade

我正在为“客户”表构建搜索功能,由于某种原因,当我搜索具有特定手机号码的条目时,即使该数据存在,它也不会显示。我只能通过“移动”属性来体验这一点,而其他所有属性都很好。

这是我的“客户”表架构:

 Schema::create('customers', function (Blueprint $table) {
        $table->id();
        $table->string('firstName')->nullable();
        $table->string('lastName');
        $table->string('companyName');
        $table->string('companyEmail')->unique();
        $table->string('branch')->nullable();
        $table->bigInteger('phone')->nullable();
        $table->bigInteger('mobile')->nullable();
        $table->string('address')->nullable();
        $table->string('clientType')->nullable();
        $table->string('reseller')->nullable();
        $table->string('assignedTo');
        $table->timestamps();
    });

当我尝试在PHPMyAdmin上执行相同的查询时,它会检索数据: enter image description here

但是在使用此代码时,它不会:

$results = Customer::where('firstName', 'like', '%'.$request->input('search-customer-fname'). '%')
        ->where('lastName', 'like', '%'.$request->input('search-customer-lname'). '%')
        ->where('companyName', 'like', '%'.$request->input('search-company-name'). '%')
        ->where('companyEmail', 'like', '%'.$request->input('search-company-email'). '%')
        ->where('branch', 'like', '%'.$request->input('search-company-branch'). '%')
        ->where('phone', 'like', '%'.$request->input('search-company-phone'). '%')
        ->where('mobile', 'like', '%'.$request->input('search-company-mobile'). '%')
        ->paginate(10);

die and dumping returns null

这是移动输入字段的HTML /刀片代码:

<label for="search-company-mobile">
      Mobile: 
      <input class="form-control" type="number" name="search-company-mobile">
</label>

任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:1)

我认为您需要or在哪里...不在哪里

   $results = Customer::query();
    
    if($request->input('search-customer-fname')!=null)
    {
        $results = $results->where('firstName', 'like', '%'.$request->input('search-customer-fname'). '%');
    }

    if($request->input('search-customer-lname')!=null)
    {
        $results = $results->where('lastName', 'like', '%'.$request->input('search-customer-lname'). '%');
    }
     if($request->input('search-company-name')!=null)
    {
        $results = $results->where('companyName', 'like', '%'.$request->input('search-company-name'). '%');
    }
       if($request->input('search-company-email')!=null)
    {
        $results = $results->where('companyEmail', 'like', '%'.$request->input('search-company-email'). '%');
    }
      if($request->input('search-company-branch')!=null)
    {
        $results = $results->where('branch', 'like', '%'.$request->input('search-company-branch'). '%');
    }
     if($request->input('search-company-phone')!=null)
    {
        $results = $results->where('phone', 'like', '%'.$request->input('search-company-phone'). '%');
    }
      if($request->input('search-company-mobile')!=null)
    {
        $results = $results->where('mobile', 'like', '%'.$request->input('search-company-mobile'). '%');
    }

    $results=$results->paginate(10);