get(); $total_words = UserOpenai::where('user_id', Auth::id())->sum('credits'); Cache::put('total_words_' . Auth::id(), $total_words, now()->addMinutes(360)); $total_documents = count($total_documents_finder); Cache::put('total_documents_' . Auth::id(), $total_documents, now()->addMinutes(360)); $total_text_documents = count($total_documents_finder->where('credits', '!=', 1)); Cache::put('total_text_documents_' . Auth::id(), $total_text_documents, now()->addMinutes(360)); $total_image_documents = count($total_documents_finder->where('credits', '==', 1)); Cache::put('total_image_documents_' . Auth::id(), $total_image_documents, now()->addMinutes(360)); } $total_words = Cache::get('total_words_' . Auth::id()) ?? 0; View::share('total_words', $total_words); $total_documents = Cache::get('total_documents_' . Auth::id()) ?? 0; View::share('total_documents', $total_documents); $total_text_documents = Cache::get('total_text_documents_' . Auth::id()) ?? 0; View::share('total_text_documents', $total_text_documents); $total_image_documents = Cache::get('total_image_documents_' . Auth::id()) ?? 0; View::share('total_image_documents', $total_image_documents); } return $next($request); } }