Skip to content

Instantly share code, notes, and snippets.

@afiqiqmal
Created November 1, 2017 16:51
Show Gist options
  • Save afiqiqmal/df68de75c3ff6475c4c2190adf67b760 to your computer and use it in GitHub Desktop.
Save afiqiqmal/df68de75c3ff6475c4c2190adf67b760 to your computer and use it in GitHub Desktop.
This is a sample static class for returning json
<?php
namespace App\Library;
class Message
{
public static function error($msg = 'Something went wrong', $code = 400, $reference = null)
{
return response()->json(
[
'error' => true,
'message' => $msg,
'reference' => $reference,
],
$code
);
}
public static function success($msg = 'Request Success', $code = 200, $obj = null)
{
return response()->json(
[
'error' => false,
'message' => $msg,
'data' => $obj,
],
$code
);
}
}
<?php
return Message::error("Unauthorized user. Please Contact Admin to Active", 401);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment