“message”:“调用未定义的方法Closure::getRelationExistenceQuery()",laravel

rxztt3cl  于 2022-11-26  发布在  其他
关注(0)|答案(1)|浏览(133)

我已经创建了一个从数据库获取数据的函数,但是当我用postman测试时,这个函数返回了一个错误。

public function payments(){
       $data = Investigations::whereHas(function($query){
        $query->where('name', 'LIKE', '%consultation%' );
       })->get();
    
        return $data;
}

该表包含以下列

protected $fillable = [
        "visit", "admission_id", "type", "procedure", "quantity", "price", "discount",
        "amount", "user", "instructions", "ordered", "invoiced", "reasons", "assigned_to",
        "performing_doctor", "on_credit", "comments", "credit_status", "is_walkin",
        'service_sale_id', "cancelled", 'cancel_text', "date_changed_by", "date_adjusted_from",
        "assigned_by", "assigned_on",
        'moved_from_chargesheet', 'package_id',
        "created_at",
    ];
ctrmrzij

ctrmrzij1#

我看不到有一个“姓名”栏。
'whereHas'用于在关系中查询

Investigations::whereHas('relation_name', function($query){
    $query->where('name', 'LIKE', '%consultation%' );
   })->get();

如果要在当前表中搜索,可以使用'where'。
它可以是条件或函数

Investigations::where('name', 'LIKE', '%consultation%' )->get()

                  

Investigations::where(function($query){
    $query->where('name', 'LIKE', '%consultation%' );
   })->get()

相关问题