Skip to content

Commit

Permalink
fix media process and hasOne
Browse files Browse the repository at this point in the history
  • Loading branch information
3x1io committed Oct 5, 2022
1 parent 97825d8 commit b5ebec7
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 15 deletions.
4 changes: 2 additions & 2 deletions Config/config.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

return [
'excel_import' => false,
'excel_export' => false
'excel_import' => true,
'excel_export' => true
];
2 changes: 1 addition & 1 deletion Services/Resource/Concerns/Actions/Show.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function unsetShowData($record): void
foreach($this->rows() as $row) {
if (($row->vue === 'ViltHasOne.vue') && !empty($row->relation)) {
$record->{$row->name} = $record->{$row->relation};
unset($record->{$row->name});
unset($record->{$row->relation});
}
}
}
Expand Down
28 changes: 16 additions & 12 deletions Services/Resource/Concerns/Process/Media.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace Modules\Base\Services\Resource\Concerns\Process;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;

trait Media
{
Expand All @@ -26,18 +28,20 @@ public function processMediaOnUpdate(Request $request, $record): void
foreach ($this->rows() as $field) {
if (($field->vue === 'ViltMedia.vue')) {
if ($request->{$field->name} && is_array($request->{$field->name})) {
$hasNewMedia = false;
foreach ($request->{$field->name} as $item) {
if ($item->getClientOriginalName() !== 'blob') {
$hasNewMedia = true;
}
}
if ($hasNewMedia) {
$record->clearMediaCollection($field->name);
foreach ($request->{$field->name} as $item) {
$record->addMedia($item)
->preservingOriginal()
->toMediaCollection($field->name);
$record->clearMediaCollection($field->name);
foreach ($request->{$field->name} as $key=>$item) {
if(!is_string($item)){
if($item->getClientOriginalName() === 'blob'){
$record->addMedia($item)
->usingFileName(strtolower(Str::random(10).'_'.$key.'.'.$item->extension()))
->preservingOriginal()
->toMediaCollection($field->name);
}
else {
$record->addMedia($item)
->preservingOriginal()
->toMediaCollection($field->name);
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions Services/Rows/Color.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

class Color extends Base
{

public string $vue = 'ViltColor.vue';

/**
Expand Down
20 changes: 20 additions & 0 deletions Services/Rows/Icon.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Modules\Base\Services\Rows;

use Modules\Base\Services\Rows\Abstracts\Base;

class Icon extends Base
{

public string $vue = 'ViltIcon.vue';

/**
* @param string $name
* @return static
*/
public static function make(string $name): self
{
return (new self)->name($name);
}
}

0 comments on commit b5ebec7

Please sign in to comment.