When I return with my relationship with the collection is always empty, I do have data in my database.
Client model
public function orders()
{
return $this->belongsToMany(Service::class)->withTimestamps();
}
Service model
public function clients()
{
return $this->belongsToMany(Client::class)->withTimestamps();
}
Query the relationship is always empty
$client = Client::with('orders')->firstOrFail();
My table migration;
Schema::create('client_service', function (Blueprint $table) {
$table->bigIncrements('id');
$table->unsignedBigInteger('client_id');
$table->unsignedBigInteger('service_id');
$table->timestamps();
});
I don't see how the relationship is empty using the many to many setup above.
Query log
array:2 [▼
0 => array:3 [▼
"query" => "select * from `clients` limit 1"
"bindings" => []
"time" => 0.59
]
1 => array:3 [▼
"query" => "select `services`.*, `client_service`.`client_id` as `pivot_client_id`, `client_service`.`service_id` as `pivot_service_id`, `client_service`.`created_at` as `pivot_created_at`, `client_service`.`updated_at` as `pivot_updated_at` from `services` inner join `client_service` on `services`.`id` = `client_service`.`service_id` where `client_service`.`client_id` in (1) ◀"
"bindings" => []
"time" => 1.05
]
]