live charts update added

This commit is contained in:
Anatoliy Poloz
2022-06-02 12:02:58 +00:00
parent 3cd66a54e5
commit 12e42ddddd
61 changed files with 1881 additions and 546 deletions

View File

@@ -0,0 +1,66 @@
<?php
namespace App\Http\Livewire\Diary;
use App\Models\Meal;
use App\Models\UserAttachment;
use Illuminate\Support\Facades\Auth;
use Livewire\Component;
use Livewire\WithFileUploads;
use Illuminate\Support\Facades\Storage;
class MealPhotos extends Component
{
use WithFileUploads;
public Meal $meal;
public $tmpMealPhotos = [];
public function render()
{
return view(
'livewire.diary.meal-photos',
[
'curMealPhotos' => $this->meal->photos
],
);
}
public function updatedTmpMealPhotos($values)
{
/* dd($values); */
$newPhotos = collect($values)->take(3);
$attachmentGroup = "meal_photos";
$userId = Auth::user()->id;
$filePath = $attachmentGroup . "/" . $userId . "/" . $this->meal->id;
$publicFilePath = "public/" . $filePath;
foreach($newPhotos as $photo) {
$curPhoto = $photo
->storePublicly($publicFilePath);
$fileData = [
'user_id' => $userId,
'group' => $attachmentGroup,
'original_name' => $photo->getClientOriginalName(),
'size' => $photo->getSize(),
];
$newFile = UserAttachment::updateOrCreate(
$fileData,
[
'path' => preg_replace("/public\//xi", "/storage/", $curPhoto),
'specs' => json_encode(
[
'ext' => $photo->extension(),
'original_path' => $curPhoto,
]
)
]
);
$newFile->save();
$this->meal->photos()->attach($newFile->id);
}
}
}