-2

I have many to many relationship and I'm trying to check this company's shift name already exist or not in database.

relation is below.

public function shifts()
{

        return $this->belongsToMany('App\Models\Shift');

}

public function companies()
{

      return $this->belongsToMany('App\Models\Company');

}
shaedrich
  • 5,457
  • 3
  • 26
  • 42
  • 6
    Whats the question, where is your code, what have you tried? You write, we help, we dont write code for you. – Grumpy Jul 22 '21 at 09:03

2 Answers2

2

you can check it with like below:

$company = Company::find(id)->with('shifts')->where('shiftname','shiftname')->get();

it will return record or null.

0

You can check it with

$company = Company::find(1);

$company->shifts()->where('shift_name', "yourShiftName")->get();
Dren
  • 1,239
  • 1
  • 8
  • 17