Skip to content

Commit

Permalink
Merge branch 'main' of github.com:doublethreedigital/guest-entries
Browse files Browse the repository at this point in the history
  • Loading branch information
duncanmcclean committed Oct 3, 2022
2 parents 6f889bd + 1f4ae8b commit f557d7f
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/Http/Controllers/GuestEntryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Illuminate\Routing\Controller;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Statamic\Facades\Asset;
use Statamic\Facades\AssetContainer;
use Statamic\Facades\Collection;
use Statamic\Facades\Entry;
Expand Down Expand Up @@ -202,11 +203,11 @@ protected function uploadFile(string $key, Field $field, Request $request)

/* @var \Illuminate\Http\Testing\File $file */
foreach ($uploadedFiles as $uploadedFile) {
$path = '/' . $uploadedFile->storeAs(
$path = '/'.$uploadedFile->storeAs(
isset($field->config()['folder'])
? $field->config()['folder']
: '',
now()->timestamp . '-' . $uploadedFile->getClientOriginalName(),
now()->timestamp.'-'.$uploadedFile->getClientOriginalName(),
$assetContainer->diskHandle()
);

Expand All @@ -215,6 +216,15 @@ protected function uploadFile(string $key, Field $field, Request $request)
$path = substr($path, 1);
}

// Ensure asset is created in Statamic (otherwise, it won't show up in
// the Control Panel for sites with the Stache watcher disabled).
$asset = Asset::make()
->container($assetContainer->handle())
->path($path);

$asset->save();

// Push to the array
$files[] = $path;
}

Expand Down Expand Up @@ -267,7 +277,7 @@ protected function withSuccess(Request $request, array $data = [])
{
if ($request->wantsJson()) {
$data = array_merge($data, [
'status' => 'success',
'status' => 'success',
'message' => null,
]);

Expand All @@ -283,7 +293,7 @@ protected function withErrors(Request $request, string $errorMessage)
{
if ($request->wantsJson()) {
return response()->json([
'status' => 'error',
'status' => 'error',
'message' => $errorMessage,
]);
}
Expand Down

0 comments on commit f557d7f

Please sign in to comment.