Skip to content

Commit

Permalink
Add Success and failure helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
Damiloju committed Feb 16, 2018
1 parent a06315f commit d5a966d
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions app/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,37 @@ function flash($title = null, $message = null)
}

return $flash->info($title, $message);
}

function apiSuccess(string $msg, $data, array $meta=[], bool $sendUserInfo = true)
{

$responder = config('app.apiResponse');
$responder['status'] = 0;
$responder['message'] = $msg;
$responder['data'] = $data;

return response()->json( $responder );
}

/**
* A blueprint of a failed ajax request
* @param $msg
* @param $data
* @param int $code
* @return \Illuminate\Http\JsonResponse
*/
function apiFailure(string $msg, $data, int $code = 2)
{
/**
* 4 => validation error
* 2 => internal error
* -2 => unauthorized for action
*/
$responder = config('app.apiResponse');
$responder['status'] = $code;
$responder['message'] = $msg;
$responder['data'] = $data;

return response()->json($responder);
}

0 comments on commit d5a966d

Please sign in to comment.