Skip to content

Commit ba4f07c

Browse files
optimize the relationships
1 parent 34dcc01 commit ba4f07c

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/HasFiles.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
trait HasFiles
1616
{
1717
use HasCustomAttributes;
18+
1819
/**
1920
* Files Atrributes on Save/Create
2021
*
@@ -149,7 +150,13 @@ public function isFileAttribute(string $key): bool
149150
*/
150151
public function files()
151152
{
152-
return $this->morphMany(File::class, 'model');
153+
$hasThumbnails = false;
154+
155+
foreach ($this->filesOptions ?? [] as $options)
156+
if (isset($options['thumbnail']))
157+
$hasThumbnails = true;
158+
159+
return $this->morphMany(File::class, 'model')->with($hasThumbnails ? 'file.thumbnail' : 'file');
153160
}
154161

155162
/**

0 commit comments

Comments
 (0)