1. Go to this page and download the library: Download jobmetric/laravel-unit 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 JobMetric\UnitConverter\Facades\UnitConverter;
// Convert 5 kilograms to grams
$result = UnitConverter::convert($kilogramUnitId, $gramUnitId, 5);
// Result: 5000
// Or use the helper function
$result = unitConvert($kilogramUnitId, $gramUnitId, 5);
use Illuminate\Database\Eloquent\Model;
use JobMetric\UnitConverter\HasUnit;
class Product extends Model
{
use HasUnit;
protected array $unitables = [
'weight' => 'weight',
'length' => 'length',
'width' => 'length',
'height' => 'length',
];
}
bash
# List all registered units
php artisan unit:list
# Convert a value between units
php artisan unit:convert
# Export units to file
php artisan unit:export
# Seed default units
php artisan unit:seed
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.