1. Go to this page and download the library: Download foxws/laravel-relatable 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/ */
foxws / laravel-relatable example snippets
use Foxws\Relatable\Concerns\InteractsWithRelated;
use Illuminate\Database\Eloquent\Model;
class Tag extends Model
{
use InteractsWithRelated;
}
$action->attachRelated($fastpace, score: 1.0);
$action->attachRelated($genre, score: 0.5);
// Relations are directed. Relate both ways (Action → Genre and Genre → Action),
// with a lower score back.
$action->attachRelated($genre, score: 0.5, mutual: true, mutualScore: 0.25);
// Relate exactly these models, removing the rest.
$action->syncRelated([
$fastpace,
['model' => $genre, 'score' => 0.5, 'boost' => 2.0],
]);
$action->detachRelated($genre); // only Action → Genre
$action->detachRelated($genre, mutual: true); // and Genre → Action
$action->relates; // Collection of related models, highest weight first
$action->getRelates(Video::class); // only related videos