HEX
Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.4.33
System: Linux li317-225.members.linode.com 3.10.0-1062.12.1.el7.x86_64 #1 SMP Tue Feb 4 23:02:59 UTC 2020 x86_64
User: apache (48)
PHP: 7.4.33
Disabled: NONE
Upload Files
File: /var/www/hobbyistgarage/app/Providers/AppServiceProvider.php
<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use App\Models\Article;
use App\Models\Tag;
use App\Models\Category;
use App\Models\Ad;
use Illuminate\Support\Facades\Cache;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }

    
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        //
        view()->composer('*', function ($view) {
            $ad = Ad::inRandomOrder()->limit(3)->get();
            
            $tags = Cache::remember('tags', 1440, function() {
                        return Tag::orderBy('name', 'asc')->get();
                    });
            
            $categories = Cache::remember('categories', 1440, function() {
                            return Category::whereNotIn('id', [1,2,16,7])->orderBy('name', 'asc')->get();
                        });
            
            if ($view->getName() != 'newsandreviews.show') {
                $populars = Cache::remember('populars', 1440, function() {
                    return Article::where('published',true)->orderBy('likes', 'desc')->limit(5)->get();
                });
                
                $editors = Cache::remember('editors', 1440, function() {
                    return Article::where('published',true)->where('editor_pick',true)->orderBy('likes', 'desc')->limit(5)->get();
                });
                
                $trending = Cache::remember('trending', 1440, function() {
                        return Article::where('published',true)->orderByRaw('LOG10(ABS(likes - dislike) + 1) * SIGN(likes - dislike) + (UNIX_TIMESTAMP(published_at) / 300000) DESC')->limit(5)->get();
                });
                
                $view->with('tags',$tags)->with(array("categories" => $categories, "populars" => $populars, "editors" => $editors,
                    "trending" => $trending, "ad" => $ad));
            } else {
                $view->with('tags',$tags)->with(array("categories" => $categories, "ad" => $ad));
            }
            
            
        });
        
    }
}