Home > Enterprise >  Laravel 8 - multiple where clauses must be met
Laravel 8 - multiple where clauses must be met

Time:01-27

I have a table for business and one for the employees.

I am trying to see whether a user already exists in the employee table with the same user_id and business_id, however, with my current code I am unsure how to do this.

My code:

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

CodePudding user response:

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

or

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