PHP code example of ifresh / laravel-enum-translations

1. Go to this page and download the library: Download ifresh/laravel-enum-translations library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ifresh / laravel-enum-translations example snippets


namespace App\Enums;

enum Cards: string
{
    case Hearts = 'hearts';
    case Diamonds = 'diamonds';
    case Clubs = 'clubs';
    case Spades = 'spades';
}

return [
    'cards' => [
        'hearts' => 'Hearts ❤️',
        'diamonds' => 'Diamonds 💎',
        'clubs' => 'Clubs ♣️',
        'spades' => 'Spades ♠️',
    ],
];

use App\Enums\Cards;
use IFresh\EnumTranslations\EnumTranslatorFacade as EnumTranslator;

$translations = EnumTranslator::translate(Cards::class);
/*
 * [
 *   'hearts' => 'Hearts ❤️',
 *   'diamonds' => 'Diamonds 💎',
 *   'clubs' => 'Clubs ♣️',
 *   'spades' => 'Spades ♠️',
 * ]
 */

EnumTranslator::translateValue(Cards::class, Cards::Hearts); // 'Hearts ❤️'

EnumTranslator::translateValue(Cards::class, null); // ''