PHP code example of jenssegers / optimus

1. Go to this page and download the library: Download jenssegers/optimus 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/ */

    

jenssegers / optimus example snippets


use Jenssegers\Optimus\Optimus;

new Optimus(1580030173, 59260789, 1163945558);

$encoded = $optimus->encode(20); // 1535832388

$original = $optimus->decode(1535832388); // 20



namespace App\Providers;

use Jenssegers\Optimus\Optimus;
use Illuminate\Support\ServiceProvider;

class OptimusServiceProvider extends ServiceProvider
{
    public function register()
    {
        $this->app->singleton(Optimus::class, function ($app) {
            return new Optimus(1580030173, 59260789, 1163945558);
        });
    }
}



namespace App\Http\Controllers;

use Jenssegers\Optimus\Optimus;
use App\Http\Controllers\Controller;

class UserController extends Controller
{
    public function show($id, Optimus $optimus)
    {
        $id = $optimus->decode($id);
    }
}
bash
> php vendor/bin/optimus spark

Prime: 2123809381
Inverse: 1885413229
Random: 146808189
bash
> php vendor/bin/optimus spark 1580030173

Prime: 1580030173
Inverse: 59260789
Random: 1163945558