Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

monicahq/monica

23656 stars
1 code files
View monicahq/monica on GitHub

app/Services/Account/Photo/UploadPhoto.php

Open in GitHub
use App\Models\Account\Photo;
use App\Services\BaseService;
use App\Models\Contact\Contact;
 
class UploadPhoto extends BaseService
{
//
public function execute(array $data): ?Photo
{
$this->validate($data);
 
$contact = Contact::where('account_id', $data['account_id'])
->findOrFail($data['contact_id']);
 
$contact->throwInactive();
 
$array = null;
if (Arr::has($data, 'photo')) {
$array = $this->importPhoto($data);
} else {
$array = $this->importFile($data);
}
 
if (! $array) {
return null;
}
 
return tap(Photo::create($array), function ($photo) use ($contact): void {
$contact->photos()->syncWithoutDetaching([$photo->id]);
});
}
//
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.