Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Laravel 8 – multiple where clauses must be met

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

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');
        }
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading