Louisdrake
Louisdrake

Reputation: 9

Results in Laravel

Table A:

Id|name
1 |John
2 |Tom
3 |Max
4 |Paul

Table B:

Id|item|user
1 |100 | 3
2 |100 | 1

With Laravel, how can I collect just the users that are not present in table B?

Upvotes: 0

Views: 30

Answers (1)

Dilip Hirapara
Dilip Hirapara

Reputation: 15296

You need to make the relationship as HasMany

$tables = TableA::doesnthave('users')->get();

With this, You will get only those records which user does not have value in TableB

namespace App;

use Illuminate\Database\Eloquent\Model;

class TableA extends Model
{
    public function users()
    {
        return $this->hasMany('App\TableB','user','id');
    }
}

Upvotes: 1

Related Questions