forked from eatvio/eatvio-infra
live charts update added
This commit is contained in:
66
app/Http/Livewire/Diary/MealPhotos.php
Normal file
66
app/Http/Livewire/Diary/MealPhotos.php
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user