Skip to content

Commit f602add

Browse files
authored
Merge pull request #9 from sfadschm/fix-getWith
Fix getWith should always return array.
2 parents b964ae2 + b08bbd6 commit f602add

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

src/Traits/ModelTrait.php

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,19 @@ public function without($tables)
8282
*/
8383
protected function getWith(): array
8484
{
85-
return empty($this->with) ? [] : $this->with;
85+
// Ensure $this->with is set at all
86+
if (empty($this->with))
87+
{
88+
$this->with = [];
89+
}
90+
91+
// Force a single table name into an array
92+
if (! is_array($this->with))
93+
{
94+
$this->with = [$this->with];
95+
}
96+
97+
return $this->with;
8698
}
8799

88100
/**
@@ -92,7 +104,19 @@ protected function getWith(): array
92104
*/
93105
protected function getWithout(): array
94106
{
95-
return empty($this->without) ? [] : $this->without;
107+
// Ensure $this->without is set at all
108+
if (empty($this->without))
109+
{
110+
$this->without = [];
111+
}
112+
113+
// Force a single table name into an array
114+
if (! is_array($this->without))
115+
{
116+
$this->without = [$this->without];
117+
}
118+
119+
return $this->without;
96120
}
97121

98122
/**

0 commit comments

Comments
 (0)