Current File : //proc/thread-self/root/proc/self/root/home/tradevaly/www/app/helpers.php
<?php
use App\Models\WatchHistory;
use App\Models\AdminNotification;

function menuActive($routeName, $type = null)
{
    if ($type == 3) {
        $class = 'side-menu--open';
    } elseif ($type == 2) {
        $class = 'sidebar-submenu__open';
    } else {
        $class = 'active';
    }
    if (is_array($routeName)) {
        foreach ($routeName as $key => $value) {
            if (request()->routeIs($value)) {
                return $class;
            }
        }
    } elseif (request()->routeIs($routeName)) {
        return $class;
    }
}

function impressionCount($id)
{
    $item = \App\Models\Advertise::where('id',$id)->first();
    $item->impression +=1;
    $item->save();
}
function logo(){
    return App\Models\Logo::find(1)->image;
}
function settings(){
    return App\Models\Logo::find(1);
}
function child_product_count($id){
    return App\Models\Product::where('status', 1)->where('child_id', $id)->count();
}
function product_count_by_category($id){
    return App\Models\Product::where('status', 1)->where('category_id', $id)->count();
}
function package_id($id){
    return App\Models\User::find($id)->package_id;
}

function page_banner($id){
    $page_banner =  App\Models\Banner::find($id);
    return $page_banner->image;
} 
function role_name($id){
    $role_name = 'Not Found';
    $role =  App\Models\Role::findOrFail($id);
    if($role){
        $role_name = $role->name;
    }
    return $role_name;
} 
function permissions(){
    $permissions =  App\Models\Permission::all()->sortBy('sorting');
    return $permissions;
} 
function sub_menus($id){
    $permissions =  App\Models\SubMenu::where('main_menu_id',$id)->get();
    return $permissions;
} 

function after_discount($amunt,$discount){
   return $amunt - ($amunt/100*$discount);
}
function check_permision($role,$permission){
    $check = false;
    $check =  App\Models\RoleHasPermission::where('role_id',$role)->where('permission_id',$permission)->exists();
    
    return $check;
}


    function visitor_count($id)
    {
        $total_link =  WatchHistory::where('product_id', $id)->count();
        return $total_link;
    }