Created
August 19, 2023 10:51
-
-
Save mansha99/a07809befd50537a9a746f9de8d3efd6 to your computer and use it in GitHub Desktop.
Observer Pattern Laravel Controller
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Controllers; | |
use App\DTO\AddressChangeDTO; | |
use App\Http\Requests\AddressChangeRequest; | |
use App\Services\OrderService; | |
class AddressController extends Controller | |
{ | |
private $orderService; | |
public function __construct(OrderService $orderService) | |
{ | |
$this->orderService = $orderService; | |
} | |
public function updateAddress($id, AddressChangeRequest $request) | |
{ | |
$data = $request->validated(); | |
$valueObject = new AddressChangeDTO($data['line1'], $data['line2'], $data['city'], $data['pincode']); | |
$result = $this->orderService->updateAddressForOrder($id, $valueObject); | |
return response()->json($result['message'], $result['status'] == 'SUCCESS' ? 200 : 400); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment