MOON
Server: Apache
System: Linux e2e-78-16.ssdcloudindia.net 3.10.0-1160.45.1.el7.x86_64 #1 SMP Wed Oct 13 17:20:51 UTC 2021 x86_64
User: imensosw (1005)
PHP: 7.4.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: /home/imensosw/www/ezwork/app/Models/UserSoftwareTool.php
<?php

/**
 * UserSoftwareToolModel class file
 *
 * PHP Version 7.2
 *
 * @category Model
 * @package  Ez
 * @author   Imenso Software <admin@imensosoftware.com>
 * @license  http://imensosoftware/license.php GNU Public License
 * @link     http://imensosoftware.com/recipes
 */

namespace App\Models;
  
use Illuminate\Database\Eloquent\Model;
use DB;

/**
 * UserSoftwareToolModel class
 *
 * The class manage User Software Tool related queries
 *
 * @category UserSoftwareToolModel
 * @package  Ez
 * @author   Imenso Software <admin@imensosoftware.com>
 * @license  http://imensosoftware/license.php GNU Public License
 * @link     http://imensosoftware.com/recipes
 */

class UserSoftwareTool extends Model
{
    public $table = "user_software_tools";
    public $fillable = ['user_id','software_tool_id'];
    public $timestamps = false;

    /**
     * GetUserSoftwareTools function gets the software tools of a specified user
     * and return it.
     *
     * @param  int $user_id
     * @return \App\Models\Software
     */
    public static function getUserSoftwareTools($user_id)
    {
        return  \App\Models\Software::
        select("user_software_tools.*", 'software_tools.software_id', 'software_tools.tool', 'softwares.software')
            ->leftJoin('software_tools', 'software_tools.software_id', '=', 'softwares.id')
            ->leftJoin(
                'user_software_tools',
                function ($join) use ($user_id) {
                    $join->on('user_software_tools.software_tool_id', '=', 'software_tools.id')
                        ->where('user_software_tools.user_id', '=', $user_id);
                }
            )
        ->orderBy('softwares.id', 'asc')->get()->toArray();
    }


    /**
     * GetUserSoftwareToolCount function gets count of the software tools of a specified user
     * and return it.
     *
     * @param  int user_id
     * @return \App\Models\UserSoftwareTool
     */
    public static function getUserSoftwareToolCount($user_id)
    {
        return UserSoftwareTool::where('user_id', $user_id)->count();
    }

    /**
     * GetUserSoftwareCount function gets count of the software of a specified user
     * and return it.
     *
     * @param  int user_id
     * @return \App\Models\Software
     */
    public static function getUserSoftwareCount($user_id)
    {
        return \App\Models\Software::
        select("softwares.*", DB::raw('count(user_software_tools.id) as userSoftwareCount'))
            ->leftJoin('software_tools', 'software_tools.software_id', '=', 'softwares.id')
            ->leftJoin(
                'user_software_tools',
                function ($join) use ($user_id) {
                    $join->on('user_software_tools.software_tool_id', '=', 'software_tools.id')
                        ->where('user_software_tools.user_id', '=', $user_id);
                }
            )
        ->groupBy('softwares.id')->get()->toArray();
    }
}