コード例 #1
0
 public function show($id)
 {
     $cacheTag = ['products'];
     $cacheKey = $id;
     $response = Cache::tags($cacheTag)->remember($cacheKey, 60 * 24 * 7, function () use($id) {
         $_model = Products::select(['category_id', 'name', 'price', 'description', 'more', 'image', 'active', 'created_at', 'updated_at'])->where('company_id', config('global.companies.current.id'))->where('id', $id);
         if ($_model->count() > 0) {
             return $_model->first()->toArray();
         } else {
             return false;
         }
     });
     if (!$response) {
         Cache::tags($cacheTag)->forget($cacheKey);
         return new \Exception("Houve um erro ao localizar registro (id not found)");
     }
     return $response;
 }
コード例 #2
0
 public function products()
 {
     $count = Products::select(\DB::raw('count(id) as total'))->where('company_id', config('global.companies.current.id'))->count();
     return $this->jsonResponse(['data' => $count]);
 }