-
app/Services/Account/Photo/UploadPhoto.php
Open in GitHubuse 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]); }); } // }