Skip to content

Commit

Permalink
fix callback relation definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgergo committed Feb 2, 2023
1 parent 4320d09 commit 8a72ecf
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 39 deletions.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/build/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"src": "resources/js/app.css"
},
"resources/js/app.js": {
"file": "assets/app-a63befa8.js",
"file": "assets/app-ba2632e7.js",
"src": "resources/js/app.js",
"isEntry": true,
"css": [
Expand Down
10 changes: 3 additions & 7 deletions resources/js/Components/Form/Editor/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<HorizontalRule :editor="editor"/>
<CodeBlock :editor="editor"/>
<Blockquote :editor="editor"/>
<Media v-if="with_media" :editor="editor" :url="media_url"/>
<Media v-if="media !== null" :editor="editor" :config="media"/>
</div>
<History :editor="editor"/>
</div>
Expand Down Expand Up @@ -93,12 +93,8 @@
type: String,
default: '',
},
with_media: {
type: Boolean,
default: false,
},
media_url: {
type: String,
media: {
type: Object,
default: null,
},
label: {
Expand Down
11 changes: 6 additions & 5 deletions resources/js/Components/Form/Editor/Media.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
</button>
<Media
ref="media"
multiple
:url="url"
:title="__('Media')"
:url="config.url"
:title="config.label"
:filters="config.filters"
:multiple="config.multiple"
:modelValue="selection"
@update:modelValue="handle"
></Media>
Expand All @@ -23,8 +24,8 @@
},
props: {
url: {
type: String,
config: {
type: Object,
required: true,
},
editor: {
Expand Down
2 changes: 1 addition & 1 deletion resources/js/Components/Media/Media.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
@dragleave.prevent="dragging = false"
@drop.prevent="handleFiles($event.dataTransfer.files)"
>
<Filters :query="query" :filters="filters" @update:query="fetch"/>
<Filters v-if="filters.length > 0" :query="query" :filters="filters" @update:query="fetch"/>
<div class="media-item-list-wrapper" :class="{ 'is-sidebar-open': value.length > 0 }">
<div class="media-item-list__body">
<Queue ref="queue" :url="url" @processed="handleProcessed"/>
Expand Down
3 changes: 1 addition & 2 deletions src/Fields/Editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,7 @@ public function toInput(RootRequest $request, Model $model): array
{
return array_merge(parent::toInput($request, $model), [
'config' => $this->config,
'media_url' => is_null($this->media) ? null : $this->media->resolveUri($request),
'with_media' => ! is_null($this->media),
'media' => is_null($this->media) ? null : $this->media->toInput($request, $model),
]);
}
}
8 changes: 5 additions & 3 deletions src/Fields/Relation.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,11 +319,13 @@ public function resolveValue(RootRequest $request, Model $model): mixed
public function getValue(RootRequest $request, Model $model): mixed
{
if ($this->relation instanceof Closure) {
if ($model->relationLoaded($this->name)) {
return $model->getAttribute($this->name);
$name = sprintf('__root_%s', $this->name);

if (! $model->relationLoaded($name)) {
$model->setRelation($name, call_user_func_array($this->relation, [$model])->getResults());
}

return call_user_func_array($this->relation, [$model]);
return $model->getAttribute($name);
}

return $model->getAttribute($this->relation);
Expand Down

0 comments on commit 8a72ecf

Please sign in to comment.