update contact recode and clean up

This commit is contained in:
hazim
2019-03-07 15:31:16 +08:00
parent 4848e1bd5b
commit 46fe8430ef
16 changed files with 572 additions and 6 deletions
@@ -8,9 +8,23 @@ use Illuminate\Http\Request;
class UpdateContact
{
/** @var Contact */
private $repository;
/**
* UpdateContact constructor.
* @param Contact $repository
*/
public function __construct(Contact $repository)
{
$this->repository = $repository;
}
public function execute(Request $request, int $type, string $reference) {
$contact = $request->method() === 'PUT' ? Contact::findOrFail($request->input('id')) : new Contact;
$contact = $this->repository->findOrFail($id);
$contact->type = $type;
$contact->reference_id = $reference;
@@ -19,6 +33,11 @@ class UpdateContact
$contact->contact = $request->input('contact');
$contact->email = $request->input('email');
$contact = $request->method() === 'PUT' ? Contact::findOrFail($request->input('id')) : new Contact;
if($contact->save()){
return new ContactResource($contact);
}