Support the ongoing development of Laravel.io →
Database
Last updated 2 years ago.
0

Highlighted part:

where( DB::raw('1'), '<', function ($q) {
  $q->from('items as i2')
      ->selectRaw('count(id)')
      ->whereRaw('i1.name = i2.name');
})

or if it's defined in model scope, then you may use this:

$table = 'i1';
...
where( DB::raw('1'), '<', function ($q) use ($table) {
  $q->from("{$this->table} as i2")
      ->selectRaw("count({$this->getKeyName})")
      ->whereRaw("{$table}.name = i2.name");
})
Last updated 2 years ago.
0

Thanks very much! I'm using your first example and it works.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.