Last active
April 12, 2020 13:12
-
-
Save csinghdev/84810412ba945395469c8af63bfeafed to your computer and use it in GitHub Desktop.
Response management functions in 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
use Illuminate\Foundation\Bus\DispatchesJobs; | |
use Illuminate\Foundation\Validation\ValidatesRequests; | |
use Illuminate\Routing\Controller as BaseController; | |
use MarcinOrlowski\ResponseBuilder\ResponseBuilder; | |
class Controller extends BaseController | |
{ | |
use AuthorizesRequests, DispatchesJobs, ValidatesRequests; | |
public function respond($data, $msg = null) { | |
return ResponseBuilder::asSuccess()->withData($data)->withMessage($msg)->build(); | |
} | |
public function respondWithMessage($msg) { | |
return ResponseBuilder::asSuccess()->withMessage($msg)->build(); | |
} | |
public function respondWithError($api_code, $http_code) { | |
return ResponseBuilder::asError($api_code)->withHttpCode($http_code)->build(); | |
} | |
public function respondBadRequest($api_code) { | |
return $this->respondWithError($api_code, 400); | |
} | |
public function respondUnAuthorizedRequest($api_code) { | |
return $this->respondWithError($api_code, 401); | |
} | |
public function respondNotFound($api_code) { | |
return $this->respondWithError($api_code, 404); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment