Skip to content

Commit

Permalink
Implement multiple photos
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc Geurts committed Jan 23, 2024
1 parent ce5c6ce commit dde3e06
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 5 deletions.
4 changes: 3 additions & 1 deletion app/Livewire/People/Add/Person.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function savePerson()
$image_name = $person->id . '_001_' . now()->format('YmdHis') . '.' . $image_type;

// delete old photos
File::delete(File::glob(storage_path('app/public/*/' . $person->id . '_001_*.*')));
File::delete(File::glob(storage_path('app/public/*/' . $person->id . '_001_*.webp')));

// resize (new) photo, add watermark and save it
$manager = new ImageManager(new Driver());
Expand All @@ -71,6 +71,8 @@ public function savePerson()

$person->update(['photo' => $image_name]);

$this->dispatch('photo_updated');

// reset photo upload input
$this->personForm->image = null;
$this->personForm->iteration++;
Expand Down
4 changes: 4 additions & 0 deletions app/Livewire/People/Add/Photo.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ public function savePhoto()
if ($new_image) {
$new_image->save(public_path('storage/photos/' . $image_name));

if ($this->person->photo == null) {
$this->person->update(['photo' => $image_name]);
}

// reset photo upload input
$this->photoForm->image = null;
$this->photoForm->iteration++;
Expand Down
4 changes: 4 additions & 0 deletions app/Livewire/People/Ancestors.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ class Ancestors extends Component

public $count_max = 10;

protected $listeners = [
'photo_updated' => 'mount',
];

public function increment()
{
if ($this->count < $this->count_max) {
Expand Down
4 changes: 4 additions & 0 deletions app/Livewire/People/Descendants.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ class Descendants extends Component

public $count_max = 10;

protected $listeners = [
'photo_updated' => 'mount',
];

public function increment()
{
if ($this->count < $this->count_max) {
Expand Down
2 changes: 1 addition & 1 deletion app/Livewire/People/Edit/Profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function saveProfile()
$image_name = $this->person->id . '_001_' . now()->format('YmdHis') . '.' . $image_type;

// delete old photos
File::delete(File::glob(storage_path('app/public/*/' . $this->person->id . '_001_*.*')));
File::delete(File::glob(storage_path('app/public/*/' . $this->person->id . '_001_*.webp')));

// resize (new) photo, watermark and save it
$manager = new ImageManager(new Driver());
Expand Down
11 changes: 8 additions & 3 deletions app/Livewire/People/Photos.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Photos extends Component
public $maxImages = 5;

protected $listeners = [
'person_updated' => 'render',
'photo_updated' => 'mount',
];

public function previousImage()
Expand Down Expand Up @@ -51,8 +51,13 @@ public function deleteImage()

toast()->success(__('person.photo_deleted') . '.', __('app.delete'))->push();

$this->mount();
$this->dispatch('person_updated');
$files = File::glob(public_path() . "/storage/photos/{$this->person->id}_*.webp");

$this->person->update([
'photo' => $files ? substr($files[0], strrpos($files[0], '/') + 1) : null,
]);

$this->dispatch('photo_updated');
}

public function mount()
Expand Down
Binary file removed storage/app/public/photos/1_001_demo.webp
Binary file not shown.
Binary file removed storage/app/public/photos/1_002_demo.webp
Binary file not shown.
Binary file removed storage/app/public/photos/1_003_demo.webp
Binary file not shown.

0 comments on commit dde3e06

Please sign in to comment.