Reputation:
I'm attempting to build up a query in Laravel.
I have two tables, with the following attirbuteds
User
TenantPreferance
I'm trying to get a collection of data from users of a certain type where id of the user, matches the user_id in preferences.
But I get this error
Undefined property: Illuminate\Database\Eloquent\Builder::$id
$tenants = User::where('userType', 'tenant');
$Prefereances = TenantPreferance::where($tenants->id, $Prefereances->user_id);
$users = $Prefereances->get();
Upvotes: 0
Views: 1285
Reputation: 488
$tentants = User::with('TenantPreferance')->where('userType', 'tenant')->get();
where TenantPreferance is the relationship name
Upvotes: 0
Reputation: 28
for : $tenants = User::where('userType', 'tenant'); must add: first()
$tenants = User::where('userType', 'tenant')->first();
or : get()
$tenants = User::where('userType', 'tenant')->get();
Upvotes: 1
Reputation: 1
You need to actually run the built sql. You also need to get a singular event of it out. So im using first() in this instance. Like this
$tenants = User::where('userType', 'tenant')->first();
Upvotes: 0