Skip to content

Latest commit

 

History

History
270 lines (224 loc) · 9.19 KB

README.md

File metadata and controls

270 lines (224 loc) · 9.19 KB

Laravel Utils

Packagist License Total Downloads

Introduction

  • This package provides helpful and neccessary helper functions which can be useful in your Laravel projects.

Installation & Usage

Requires PHP 8.0+ | Laravel 8.0+

Require Laravel Utils using Composer:

composer require --dev vcian/laravel-utils

Usage:

You can access different helper functions mentioned below.

use Vcian\LaravelUtils\LaravelUtils;

General Functions

  1. Grab the application name
    LaravelUtils::appName()
  2. Get logged in user
    LaravelUtils::loggedInUser()
  3. Check login status
    LaravelUtils::checkAuth()
  4. Encrypt given value
    LaravelUtils::encryption($string)
  5. Decrypt given value
    LaravelUtils::decryption($string)
  6. Get server user agent
    LaravelUtils::getUserAgent()

Database Functions

  1. Check database connection
    LaravelUtils::checkDbConnection()
  2. Print query
    LaravelUtils::printQuery($string)
  3. Select query
    LaravelUtils::selectQuery($table, $columns, $conditions, $orderBy, $limit)
  4. Insert record
    LaravelUtils::insertQuery($table, $data)
  5. Update record
    LaravelUtils::updateQuery($table, $data, $conditions)
  6. Delete record
    LaravelUtils::deleteQuery($table, $conditions)
  7. Filter query with condition
    LaravelUtils::filterQuery($table, $column, $operator, $value)
  8. Get records in specific order
    LaravelUtils::orderResults($table, $column, $direction)
  9. Count number of records in table
    LaravelUtils::countResults($table)
  10. Join query for tables
    LaravelUtils::joinTables($table1, $table2, $column1, $column2)
  11. Get paginate results
    LaravelUtils::getPaginatedResults($query, $perPage)

Laravel Custom Route Functions

  1. Searches sub-directories
    LaravelUtils::includeRouteFiles($folder)
  2. Get route URL
    LaravelUtils::getRouteUrl($url, $urlType, $separator)

API Connection/Response Functions

  1. Generate API token
    LaravelUtils::generateApiToken()
  2. CURL request
    LaravelUtils::callAPI($url, $method, $data, $headers)
  3. Get Json Response from API
    LaravelUtils::jsonResponseFromAPI($data, $statusCode)

CSS Functions

  1. Get css and js path
    LaravelUtils::customAsset($path)
  2. Get active menu
    LaravelUtils::activeMenu($route, $page)
  3. Generate random color
    LaravelUtils::getRandomColor()

Array Search Function

  1. Search in array
    LaravelUtils::arrayPartialSearch($array, $keyword)

Data Conversion Functions

  1. Convert object to array
    LaravelUtils::objectToArray($collection)
  2. Get Json to array
    LaravelUtils::jsonToArray($names)
  3. CSV to ARRAY (Convert file CSV to array)
    LaravelUtils::csvToArray($filename)
  4. Array to CSV file
    LaravelUtils::arrayToCsv($data, $fileName)

Date & Time Functions

  1. Get current timestamp in the specified timezone
    LaravelUtils::getCurrentTimestamp($timezone)
  2. Get current year
    LaravelUtils::getCurrentYear()
  3. Get current month
    LaravelUtils::getCurrentMonth()
  4. Get current date
    LaravelUtils::getCurrentDate()
  5. Get sum of time
    LaravelUtils::timeSumCalculation($times)
  6. Get hours difference
    LaravelUtils::getHoursDifference($createdDate)
  7. Get days difference
    LaravelUtils::getDaysDiff($date1, $date2)
  8. Get date range
    LaravelUtils::getDateRange($startDate, $endDate, $format)
  9. Convert timestamp into date
    LaravelUtils::convertTimeStampIntoDate($timestamp, $format)
  10. Convert local time to UTC
    LaravelUtils::convertLocalToUTC($currentTimeZone, $date)
  11. Convert UTC to local
    LaravelUtils::convertUTCtoLocal($currentTimeZone, $date)
  12. Time percentage calculation
    LaravelUtils::timePercentageCal($totalTime, $usedTime)
  13. Divide time
    LaravelUtils::divideTime($time, $count)
  14. Convert time to seconds
    LaravelUtils::timeToSec($time)
  15. Convert time to minute
    LaravelUtils::timeToMin($time)
  16. Get hours between two dates
    LaravelUtils::checkHoursBetweenTwoDates($startDate, $endDate)
  17. Convert timestamp to min
    LaravelUtils::timestampToMin($time)
  18. Calculate Age (Date Format should be 'd-m-y')
    LaravelUtils::calculateAge($dateOfBirth)

Location Functions

  1. Get user location
    LaravelUtils::getUserLocation()
  2. Get latitute and logitute based on zip code
    LaravelUtils::zipCodeBaseGetLatLong($zipCode)
  3. Calculate Distance
    LaravelUtils::calculateDistance($lat1, $lon1, $lat2, $lon2, $unit)

String Functions

  1. Print a character
    LaravelUtils::printChar($string)
  2. Convert a string to title case
    LaravelUtils::toTitleCase($string)
  3. Check if the specified string starts with the given prefix
    LaravelUtils::startsWith($string, $prefix)
  4. Check if the specified string ends with the given suffix
    LaravelUtils::endsWith($string, $suffix)
  5. Explode a string into an array
    LaravelUtils::explodeData($delimiter, $string)
  6. Implode a array into a string
    LaravelUtils::implodeData($delimiter, $array)
  7. Search a string for a specific pattern
    LaravelUtils::pregMatch($pattern, $string)
  8. Replace a pattern in a string
    LaravelUtils::pregReplace($replaceWord, $replaceWith, $string)
  9. Remove space between words
    LaravelUtils::pregRemoveSpace($string)
  10. Truncate text from given text and put the suffix in the text
    LaravelUtils::truncateText($text, $length, $suffix)
  11. Get a string between specific characters
    LaravelUtils::getBetweenString($string, $start, $end)
  12. Format phone number
    LaravelUtils::formatPhoneNumber($phoneNumber)
  13. Get error response
    LaravelUtils::errorResponse($message, $statusCode)
  14. Link Formating
    LaravelUtils::linkFormatting($link)

Image/File Functions

  1. Upload Image
    LaravelUtils::uploadImage($request, $inputName, $uploadPath, $oldFileName)
  2. Upload multiple images
    LaravelUtils::uploadMultipleImage($request, $inputName, $uploadPath, $oldFileName)
  3. Upload file to local storage
    LaravelUtils::uploadFileToLocalTemp($request)
  4. Copy file to another path
    LaravelUtils::copyFileToAnotherPath($from, $to)
  5. Delete file from given location
    LaravelUtils::deleteFile($destinationPath, $oldFileName)
  6. Delete file by path
    LaravelUtils::deleteFileByPath($path)
  7. Convert image into Base64
    LaravelUtils::imageToBase64($imagePath)
  8. Compress Image
    LaravelUtils::compressImage($sourcePath, $destinationPath, $quality)
  9. Resize Image
    LaravelUtils::resizeImage($sourcePath, $destinationPath, $width, $height)
  10. Crop Image
    LaravelUtils::cropImage($sourcePath, $destinationPath, $width, $height, $x, $y)
  11. Generate a unique file name
    LaravelUtils::generateUniqueFileName($extension)
  12. Get File
    LaravelUtils::getFile($fileName, $basePath)
  13. Get the extension of the specified file
    LaravelUtils::getFileExtension($fileName)
  14. Generate URL for an uploaded file
    LaravelUtils::getUploadedFileUrl($path)
  15. Print XML in readable format
    LaravelUtils::readXMLFile($file)
  16. Create Folder
    LaravelUtils::createFolder($destinationPath)
  17. Delete Folder
    LaravelUtils::deleteFolder($destinationPath, $folderName)

Value/Type Conversion Functions

  1. Convert value in integer
    LaravelUtils::convertValueInteger($value)
  2. Convert float value to round value
    LaravelUtils::convertToRound($value, $precision)
  3. Convert foot/inches to centimeter
    LaravelUtils::convertToCM($feet, $inches)
  4. Convert centimeter to inches
    LaravelUtils::convertToInches($cm)
  5. Convert pounds to kilogram
    LaravelUtils::convertToKG($pounds)
  6. Convert kilogram to pounds
    LaravelUtils::convertToPounds($kg)

VAT/Discount Calculation Functions

  1. Calculate vat on price
    LaravelUtils::calculateVatOnPrice($priceExcludingVat, $vat)
  2. Discount on price
    LaravelUtils::discountOnPrice($price, $discount)

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

   We believe in 
        👇
      ACT NOW
  PERFECT IT LATER
CORRECT IT ON THE WAY.

Security

If you discover any security-related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.