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();
    }
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();
    }
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 ( ) ; }
Search media filse

@param string $searchTerm Search Query
@param int    $page       Which page of the pagination we currently
@param string $fromDate   From date ex. 2016-31-12
@param string $toDate     To date ex. 2017-31-12
@param string $mediaType  Media type to search for, ex. 'image'. 'all' for all media types
@param string $orderBy    Column name
@param string $orderType  DESC or ASC
@param int    $page

@return mixed

@throws Exception If no columns could be found
Search media filse