【问题标题】:Laravel 8 - multiple where clauses must be metLaravel 8 - 必须满足多个 where 子句
【发布时间】:2022-01-27 07:09:21
【问题描述】:

我有一张商务桌和一张员工桌。

我正在尝试查看员工表中是否已经存在具有相同 user_id 和 business_id 的用户,但是,使用我当前的代码我不确定如何执行此操作。

我的代码:

if (BusinessEmployee::where('user_id', Auth::user()->id)->where('business_id', $business->id)) {
        dd('already in business');
    }

【问题讨论】:

  • 你可以使用->first()->count()

标签: mysql laravel


【解决方案1】:
if (BusinessEmployee::where('user_id', Auth::user()->id)->where('business_id', $business->id)->exists()) {
        dd('already in business');
}

$business = BusinessEmployee::where('user_id', Auth::user()->id)->where('business_id', $business->id);
        
        if($business->exists())
        {
          dd('already in business');
        }

【讨论】:

    猜你喜欢
    • 2017-05-12
    • 2020-09-28
    • 2018-09-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-17
    • 1970-01-01
    相关资源
    最近更新 更多