Where clause on two relationships Hello,
I got a Database like this:
Customers:
id, name
Inquiries:
id customer_id
Bookings:
id inquiry_id
Now i want to search all customers who made a booking, but i don't know how... can you help me?
Think Relationships-
A Customer has Many Inquiries
An Inquiry has has one / many bookings (you decide)
Now echoing @m165437 answer-
// Retrieve all customers that have at least one booking...
$customersWithBookings = App\Customer::has('bookings')->get();
Thanks guys, but i get a errormessage
BadMethodCallException
Call to undefined method App\Customer::has()
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Customer extends Model
{
public function inquiries() {
return $this->hasMany(Inquiry::class);
}
}
can't get bookings without going through inquiries first, since a booking belongs to an inquiry and not the customer (directly)
okay thanks, but this doesn't solve the problem because i still get a methodnotfound exception
no also the same error :(
Please sign in or create an account to participate in this conversation.