🧠 What is Helper?

A Helper is a file containing a few small functions that simplify the process. Instead of writing the same code every time you use it in a different location, you can put it here and call upon it whenever you need it.

🧰 Some functions

πŸ”Ή format_price($price, $currency = 'EGP')

used:

You coordinate the price and add the currency at the end.

πŸ“„ code:

function format_price($price, $currency = 'EGP') {
    return number_format($price, 2) . ' ' . $currency;
}

πŸ”Ή limit_text($text, $limit = 50)

used:

To shorten long text and add ... if it exceeds the limit.

πŸ“„ code:

use Illuminate\Support\Str;

function limit_text($text, $limit = 50) {
    return strlen($text) > $limit ? substr($text, 0, $limit) . '...' : $text;
}

πŸ”Ή time_ago($date)

used:

To show how long ago a date was (e.g., "2 hours ago", "3 days ago").

πŸ“„ code:

use Carbon\Carbon;

function time_ago($date) {
    return Carbon::parse($date)->diffForHumans();
}

πŸ”Ή uuid()