1. Go to this page and download the library: Download x-laravel/fuzzy-similarity 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/ */
x-laravel / fuzzy-similarity example snippets
use Illuminate\Database\Eloquent\Model;
use XLaravel\FuzzySimilarity\Attributes\FuzzyOn;
use XLaravel\FuzzySimilarity\Concerns\FuzzyComparable;
use XLaravel\FuzzySimilarity\Contracts\HasFuzzySimilarity;
#[FuzzyOn('name')]
#[FuzzyOn(['name', 'city'], slot: 'location')]
class Company extends Model implements HasFuzzySimilarity
{
use FuzzyComparable;
}
#[FuzzyOn('title')]
class Article extends Model implements HasFuzzySimilarity
{
use FuzzyComparable;
}
$company->fuzzySimilarityTo($otherCompany); // default slot
$company->fuzzySimilarityTo($otherCompany, slot: 'location');
$company->fuzzySimilarityTo($article); // Company name vs Article title
$company->fuzzySimilarityTo('Acme Corporation'); // plain string
$company->fuzzySimilarityTo('Corporation Acme', algorithm: 'token_set');