app/Models/Customer.php
/**
     * Search all fields
     * @param $search_terms string The term to search or terms seperated with a space
     * @return Builder
     */
Search all fields
@param $search_terms string The term to search or terms seperated with a space
@return Builder
Search all fields @param $search_terms string The term to search or terms seperated with a space @return Builder
public static function search($search_terms)
    {
        $term = "";
        $search_function = function (Builder $query) use (&$term) {
            $query->orWhere('firstname', 'LIKE', '%' . $term . '%');
            $query->orWhere('lastname', 'LIKE', '%' . $term . '%');
            $query->orWhere('email', 'LIKE', '%' . $term . '%');
            $query->orWhere('telephone', 'LIKE', '%' . $term . '%');
            $query->orWhere('fax', 'LIKE', '%' . $term . '%');
        };
        $search_terms = explode(" ", $search_terms);
        if (count($search_terms) == 1) {
            $term = $search_terms[0];
            return Customer::where($search_function);
        } else {
            $term = $search_terms[0];
            $lastQuery = Customer::where($search_function);
            for ($i = 1; $i < count($search_terms); $i++) {
                $term = $search_terms[$i];
                $lastQuery = $lastQuery->where($search_function);
            }
            return $lastQuery;
        }
    }
public static function search ( $ search_terms ) { $ term = " " ; $ search_function = function ( Builder $ query ) use ( & $ term ) { $ query -> orWhere ( 'firstname' , 'LIKE' , '%' . $ term . '%' ) ; $ query -> orWhere ( 'lastname' , 'LIKE' , '%' . $ term . '%' ) ; $ query -> orWhere ( 'email' , 'LIKE' , '%' . $ term . '%' ) ; $ query -> orWhere ( 'telephone' , 'LIKE' , '%' . $ term . '%' ) ; $ query -> orWhere ( 'fax' , 'LIKE' , '%' . $ term . '%' ) ; } ; $ search_terms = explode ( " " , $ search_terms ) ; if ( count ( $ search_terms ) == 1 ) { $ term = $ search_terms [ 0 ] ; return Customer :: where ( $ search_function ) ; } else { $ term = $ search_terms [ 0 ] ; $ lastQuery = Customer :: where ( $ search_function ) ; for ( $ i = 1 ; $ i < count ( $ search_terms ) ; $ i ++ ) { $ term = $ search_terms [ $ i ] ; $ lastQuery = $ lastQuery -> where ( $ search_function ) ; } return $ lastQuery ; } }
Search all fields
 @param $search_terms string The term to search or terms seperated with a space
 @return Builder
Search all fields @param $search_terms string The term to search or terms seperated with a space @return Builder