Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion resources/views/forms/fields/file.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<input
type="file"
id="{{ $field->handle }}-field"
name="{{ $field->handle }}[]"
name="{{ $field->handle }}{{ $field->settings['multiple'] ? '[]' : ''}}"
accept="{{ $field->settings['accept'] ?? null }}"
{{ $field->settings['multiple'] ? 'multiple': null }}
/>
Expand Down
14 changes: 14 additions & 0 deletions src/Fieldtypes/FileFieldtype.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ public function persistRelationship($model, Field $field)
$oldValues = $model->{$field->handle}->pluck('id');
$newValues = collect();

$files = is_array($files) ? $files : [$files];

foreach ($files as $key => $file) {
foreach ((array) $field->settings['directory'] as $data) {
/**
Expand All @@ -114,6 +116,18 @@ public function persistRelationship($model, Field $field)
// --
$model->{$field->handle}()->detach($oldValues);
$model->{$field->handle}()->attach($newValues);
} else if (request()->filled($field->handle)) {
$oldValues = isset($model->{$field->handle}) ? $model->{$field->handle}->pluck('id') : [];
$newValues = collect($value ?? request()->input($field->handle))
->mapWithKeys(function ($value) use ($field) {
return [
$value['id'] => [
'field_id' => $field->id,
],
];
});
$model->{$field->handle}()->wherePivot('field_id', $field->id)->detach($oldValues);
$model->{$field->handle}()->attach($newValues);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Http/Controllers/Web/FileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function index($uuid, $name)
return redirect()->to('/file/'.$uuid.'/'.$file->name.'?'.http_build_query($params));
}

if (in_array($file->mimetype, ['image/jpeg', 'image/gif', 'image/png'])) {
if (in_array($file->mimetype, ['image/jpeg', 'image/gif', 'image/png', 'image/webp'])) {
return $this->imageResponse($file, $params);
}

Expand All @@ -32,7 +32,7 @@ public function index($uuid, $name)

return Storage::disk($file->disk->handle)->response(
$file->location,
$file->name,
$file->name.'.'.$file->extension,
[
'Content-Type' => $file->mimetype,
]
Expand Down