Merge pull request #44 from CyberAli1989/master

Add helper functions for standard JSON responses
master
A1Gard 2 months ago committed by GitHub
commit 6dced06316
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -14,7 +14,8 @@ use Illuminate\Support\Facades\Route;
* @param $langCode string code like fa
* @return bool
*/
function langIsRTL($langCode) {
function langIsRTL($langCode)
{
$rtlLanguages = [
'ar', // Arabic
'arc', // Aramaic
@ -44,6 +45,7 @@ function langIsRTL($langCode) {
return in_array(strtolower($langCode), $rtlLanguages);
}
/**
* @param $lang string code like fa
* @return string
@ -251,7 +253,8 @@ function logAdmin($method, $cls, $id): void
]);
}
function gfx(){
function gfx()
{
return \App\Models\Gfx::pluck('value', 'key');
}
@ -472,6 +475,7 @@ function getAdminRoutes()
return $routes;
}
/**
* get all client routes array
* @return array
@ -784,6 +788,7 @@ function getGroupBySetting($key)
{
return Group::where('id', getSetting($key) ?? 1)->first();
}
/**
* get group by setting key
* @param $key
@ -817,3 +822,62 @@ function getCategoryProductBySetting($key, $limit = 10)
return Category::where('id', getSetting($key) ?? 1)->first()
->products()->where('status', 1)->limit($limit)->get();
}
/**
* @param null $data
* @param null $message
* @param null $metaTitle
* @param null $metaDescription
* @param null $metaImage
* @param null $metaSourceImage
* @param null $ogUrl
* @param null $ogType
* @param string $ogLocate
* @param null $canonical_url
* @return \Illuminate\Http\JsonResponse
*/
function success($data = null, $message = null, $meta = [], $og = [], $twitter = [], $canonical_url = null, $jsonLd = null)
{
$defaultMeta = [
'title' => null,
'description' => null,
'image' => null,
'secure_image' => null,
];
$defaultOg = [
'url' => null,
'type' => null,
'site_name' => env('APP_NAME'),
'description' => null,
'locate' => 'fa_IR'
];
$defaultTwitter = [
'card' => 'summary_large_image',
'site' => '@yourTwitterHandle',
'title' => null,
'description' => null,
'image' => null,
];
return response()->json([
"success" => true,
"message" => $message,
"data" => $data,
"meta" => array_merge($defaultMeta, $meta),
"og" => array_merge($defaultOg, $og),
"twitter" => array_merge($defaultTwitter, $twitter),
"canonical_url" => $canonical_url,
]);
}
function errors($errors, $status = 422, $message = null, $data = null)
{
return response()->json([
"success" => false,
"errors" => $errors,
"message" => $message,
"data" => $data,
], $status);
}

Loading…
Cancel
Save