50 lines
1.1 KiB
PHP
50 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use Auth;
|
|
use App\Product;
|
|
|
|
/**
|
|
* 提供資料給前端js使用
|
|
*
|
|
* Class AppJsObjectService
|
|
* @package App\Services
|
|
*/
|
|
class AppJsObjectService
|
|
{
|
|
public function get()
|
|
{
|
|
$option = app('Option');
|
|
$siteState = app('SiteState');
|
|
$obj = [
|
|
'locale' => app()->getLocale(),
|
|
'csrfToken' => csrf_token(),
|
|
'user' => null,
|
|
'options' => [
|
|
'googleApiKey' => $option->google_api_key,
|
|
'fbAppId' => $option->fb_app_id,
|
|
],
|
|
'translations' => [
|
|
|
|
],
|
|
'methods' => new \stdClass,
|
|
'utils' => new \stdClass
|
|
];
|
|
if(Auth::check()) {
|
|
$user = Auth::user();
|
|
$obj['user'] = [
|
|
'id' => $user->id,
|
|
'apiToken' => $user->api_token
|
|
];
|
|
}
|
|
|
|
if($siteState->isAdminArea) {
|
|
$obj['admin']['translations'] = [
|
|
'dataTables' => trans('datatables'),
|
|
];
|
|
}
|
|
return $obj;
|
|
}
|
|
}
|