Skip to content

Commit

Permalink
Improved Add persons/children/partners
Browse files Browse the repository at this point in the history
  • Loading branch information
kreaweb.be committed May 6, 2024
1 parent eb352ab commit cc21b5c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/Livewire/People/Add/Child.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public function saveChild()

if ($this->photos) {
// if needed, create team photo folder
$path = storage_path('app/public/photos/' . $this->person->team_id);
$path = storage_path('app/public/photos/' . $this->new_person->team_id);

if (! File::isDirectory($path)) {
File::makeDirectory($path, 0777, true, true);
Expand Down
4 changes: 2 additions & 2 deletions app/Livewire/People/Add/Partner.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
use App\Models\Couple;
use App\Models\Person;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\File;
use Intervention\Image\Drivers\Gd\Driver;
use Intervention\Image\ImageManager;
use Livewire\Component;
use Livewire\WithFileUploads;
use TallStackUi\Traits\Interactions;
use Illuminate\Support\Arr;

class Partner extends Component
{
Expand Down Expand Up @@ -148,7 +148,7 @@ public function savePartner()

if ($this->photos) {
// if needed, create team photo folder
$path = storage_path('app/public/photos/' . $this->person->team_id);
$path = storage_path('app/public/photos/' . $this->new_person->team_id);

if (! File::isDirectory($path)) {
File::makeDirectory($path, 0777, true, true);
Expand Down
12 changes: 6 additions & 6 deletions app/Livewire/People/Add/Person.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function savePerson()
{
if ($this->isDirty()) {
$validated = $this->personForm->validate();

$new_person = \App\Models\Person::create([
'firstname' => $validated['firstname'],
'surname' => $validated['surname'],
Expand All @@ -117,7 +117,7 @@ public function savePerson()

if ($this->photos) {
// if needed, create team photo folder
$path = storage_path('app/public/photos/' . $this->personForm->team_id);
$path = storage_path('app/public/photos/' . $this->new_person->team_id);

if (! File::isDirectory($path)) {
File::makeDirectory($path, 0777, true, true);
Expand All @@ -137,7 +137,7 @@ public function savePerson()
foreach ($this->photos as $current_photo) {
// name
$next_index = str_pad(++$last_index, 3, '0', STR_PAD_LEFT);
$image_name = $person->id . '_' . $next_index . '_' . now()->format('YmdHis') . '.' . $image_type;
$image_name = $new_person->id . '_' . $next_index . '_' . now()->format('YmdHis') . '.' . $image_type;

// resize, add watermark
$new_image = $manager->read($current_photo)
Expand All @@ -147,10 +147,10 @@ public function savePerson()

// save
if ($new_image) {
$new_image->save(storage_path('app/public/photos/' . $person->team_id . '/' . $image_name));
$new_image->save(storage_path('app/public/photos/' . $new_person->team_id . '/' . $image_name));

if (! isset($person->photo)) {
$person->update(['photo' => $image_name]);
if (! isset($new_person->photo)) {
$new_person->update(['photo' => $image_name]);
}
} else {
$this->toast()->error(__('app.save'), __('app.image_not_saved') . '.')->flash()->send();
Expand Down

0 comments on commit cc21b5c

Please sign in to comment.