public function media($searchTerm,  $fromDate = '', $toDate = '', $mediaType = '', $orderBy =  "created_at", $orderType = 'DESC', $page = 1)
    {

        $queryObject = DB::table("media");

        if($searchTerm != "") {
            $queryObject->where(
                function ($query) use ($searchTerm) {
                    $query->orWhere('filename', 'like', '%'.$searchTerm.'%');
                    $query->orWhere('title', 'like', '%'.$searchTerm.'%');
                    $query->orWhere('description', 'like', '%'.$searchTerm.'%');
                }
            );
        }

        //media type
        if ($mediaType && $mediaType != 'all') {
            $queryObject->where('type', $mediaType);
        }

        //dates
        if($fromDate && $fromDate !='null') {
            $fromDate = date('Y-m-d', strtotime($fromDate)); //need a space after dates.
        }else{
            $fromDate = false;
        }

        if($toDate && $toDate !='null') {
            $toDate = date('Y-m-d', strtotime($toDate));
        }else{
            $toDate = false;
        }

        if($fromDate && $toDate) {
            $queryObject->whereBetween('created_at', array($fromDate, $toDate));
        }else{
            if($fromDate) {
                $queryObject->whereDate('created_at', '>=', $fromDate);
            }
            if($toDate) {
                $queryObject->whereDate('created_at', '<=', $toDate);
            }
        }

        return $queryObject->orderBy($orderBy, $orderType)->get();
    }