mirror of
https://gitlab.com/omair-personal/izyim.git
synced 2026-08-19 04:14:05 +00:00
47 lines
1.0 KiB
PHP
Executable File
47 lines
1.0 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Classes\ControllersLogic\Contacts;
|
|
|
|
use App\Models\Contact;
|
|
use App\Http\Resources\Contact as ContactResource;
|
|
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 = $this->repository->findOrFail($id);
|
|
|
|
$contact->type = $type;
|
|
$contact->reference_id = $reference;
|
|
$contact->name = $request->input('name');
|
|
$contact->designation = $request->input('designation');
|
|
$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);
|
|
}
|
|
|
|
}
|
|
}
|