Skip to content

Commit

Permalink
update preview controller
Browse files Browse the repository at this point in the history
  • Loading branch information
johnpuddephatt committed Aug 18, 2023
1 parent bda864d commit 00d38a7
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions src/Http/Controllers/ViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,11 @@ public function __invoke(
// Not sure if there's a way of finding the layout that does this automatically.
// Needed to give us access to $layout->model, e.g. in accessors.

$layout->setModel($request->findModel($resourceId));
$model = $request->findModel($resourceId);
$layout->setModel($model);

$values = $request->except(["__key"]);

// if(method_exists($layout, 'imagePreviews') && count($layout->imagePreviews())) {
// foreach($layout->imagePreviews() as $field_name => $conversion_function) {
// $field_name_with_key = $request->__key . '__' . $field_name;
// if($request->file($field_name_with_key)) {
// $values[$field_name_with_key] = $conversion_function($request->file($field_name_with_key));
// }
// }
// }

// Set attributes on our layout
foreach (
$this->removeKeyPrefixFromFields($values, $request->__key)
Expand All @@ -67,16 +59,22 @@ public function __invoke(
$layout->setAttribute($key, json_decode($value) ?? $value); // json_decode needed for simple repeater field
}
} elseif (is_array($value)) {
$layout->setAttribute($key, json_encode($value));
//
$layout->setAttribute(
$key,
json_decode(json_encode($value), false)
);
// $layout->setAttribute($key, $value);
} else {
$layout->setAttribute($key, json_decode($value) ?? $value); // json_decode needed for simple repeater field
}
}

return response()->json([

Check failure on line 73 in src/Http/Controllers/ViewController.php

View workflow job for this annotation

GitHub Actions / Psalm

UndefinedDocblockClass

src/Http/Controllers/ViewController.php:73:16: UndefinedDocblockClass: Docblock-defined class, interface or enum named Illuminate\Http\JsonResponse does not exist (see https://psalm.dev/200)
"view" => view("flexible." . $layoutName, [
"layout" => $layout,
"layout" => (object) $layout,
])->render(),

"data" => $values,
"has_uploads" => !!count($request->files),
]);
Expand Down

0 comments on commit 00d38a7

Please sign in to comment.