I currently have the following problem, when i activate automaticallyEagerLoadRelationships in my Laravel Application. I have the following morphTo relation:
namespace App\Models\Tenant;
use App\Models\Base\VersionTable;
use Illuminate\Database\Eloquent\Relations\MorphTo;
class ProductVersion extends VersionTable
{
protected $table = 'tenant_product_versions';
public function product(): MorphTo
{
return $this->morphTo(
'model_data',
'tenant_product_type',
'tenant_product_id',
'id'
);
}
}
With automaticallyEagerLoading activated i get:
ProductVersion::with('product')->first()->product => null
ProductVersion::first()->product => null
It only works if i do it for example like this:
ProductVersion::first()->product()->first() => MODEL (expected result)
I have no clue why, disabling automaticallyEagerLoadRelationships also fixes the issue..does someone by any chance know what i am missing here?