コード例 #1
0
 public function index()
 {
     $cacheTag = ['companies'];
     $cacheKey = 'index';
     $role = config('global.managers.current.role');
     if ($role === 'U') {
         $cacheKey .= config('global.managers.current.id');
     }
     $cacheKey .= http_build_query(array_only(Request::all(), $this->filters));
     $response = Cache::tags($cacheTag)->remember($cacheKey, 60 * 24 * 7, function () use($role) {
         $fields = ['id', 'token', 'name', 'uri', 'active', 'created_at', 'updated_at'];
         if ($role === 'S') {
             $_db = Companies::select($fields);
         } else {
             $_model = Managers::find(config('global.managers.current.id'));
             $_db = $_model->companies()->select($fields);
         }
         return $this->filter($_db)->get()->toArray();
     });
     return $response;
 }