1. Go to this page and download the library: Download cybercog/laravel-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/ */
use Cog\Laravel\Optimus\Facades\Optimus;
// Writing this…
Optimus::connection('main')->encode($id);
// …is identical to writing this
Optimus::encode($id);
// and is also identical to writing this.
Optimus::connection()->encode($id);
// This is because the main connection is configured to be the default.
Optimus::getDefaultConnection(); // This will return main.
// We can change the default connection.
Optimus::setDefaultConnection('alternative'); // The default is now alternative.
use Cog\Laravel\Optimus\OptimusManager;
class Foo
{
protected $optimus;
public function __construct(OptimusManager $optimus)
{
$this->optimus = $optimus;
}
public function bar($id)
{
return $this->optimus->encode($id)
}
}
app()->make('Foo')->bar(20);
use Cog\Laravel\Optimus\Traits\OptimusEncodedRouteKey;
use Illuminate\Database\Eloquent\Model;
class YourModel extends Model
{
use OptimusEncodedRouteKey;
protected $optimusConnection = 'custom'; // optional
}
Route::get('url/to/{model}', function (YourModel $model) {
// ...
})->middleware('web');