### Install Laravel Mirror Package via Composer Source: https://github.com/snowlaboratory/laravel-mirror/blob/main/README.md Installs the Laravel Mirror package using Composer. ```bash composer require "snowbuilds/laravel-mirror:^0.0.3-alpha" ``` -------------------------------- ### Running the Recommendation Sync Command (Bash) Source: https://github.com/snowlaboratory/laravel-mirror/blob/main/README.md Provides the command-line instruction to manually trigger the Laravel Mirror recommendation sync process. This command calculates and stores recommendations in the database, making them available for retrieval. ```bash php artisan mirror:sync ``` -------------------------------- ### Running Package Tests (Bash) Source: https://github.com/snowlaboratory/laravel-mirror/blob/main/README.md Provides the command-line instruction to execute the test suite for the Laravel Mirror package using Composer. ```bash composer test ``` -------------------------------- ### Publish Laravel Mirror Service Provider Source: https://github.com/snowlaboratory/laravel-mirror/blob/main/README.md Publishes the configuration and assets for the Laravel Mirror package using the Artisan command. ```bash php artisan vendor:publish --provider="SnowBuilds\Mirror\MirrorServiceProvider" ``` -------------------------------- ### Registering Recommendations with Associative Array (PHP) Source: https://github.com/snowlaboratory/laravel-mirror/blob/main/README.md Demonstrates how to register recommendation algorithms and their weights using an associative array within the `registerRecommendations` method. This approach helps organize multiple custom algorithms and their corresponding weights for better readability. ```php public function registerRecommendations(): void { $this->registerStrategy(Post::class) ->using([ 'titles' => fn ($a, $b) => Algorithm::levenshtein($a->title, $b->title), 'tags' => fn ($a, $b) => Algorithm::levenshtein($a->tags, $b->tags), ]) ->weights([ 'titles' => 2, 'tags' => 1, ]); } ``` -------------------------------- ### Register Strategy Comparing Different Properties Source: https://github.com/snowlaboratory/laravel-mirror/blob/main/README.md Registers a recommendation strategy for the User model comparing different properties (biography to post title, communities to post tags) using Levenshtein and Euclidean algorithms with weights. ```php class User extends Model { use Recommendations; public function registerRecommendations(): void { $this->registerStrategy(Post::class) ->levenshtein('biography', 'title', 1); // compare biography to post title ->euclidean('communities', 'tags', 3); // compare communities to post tags } } ``` -------------------------------- ### Scheduling the Recommendation Sync Command (PHP) Source: https://github.com/snowlaboratory/laravel-mirror/blob/main/README.md Shows how to schedule the `mirror:sync` Artisan command within the Laravel kernel's `schedule` method. This is the recommended approach for production environments to automate the recommendation generation process, typically daily. ```php class Kernel extends ConsoleKernel { protected function schedule(Schedule $schedule): void { $schedule->command('mirror:sync')->daily(); } } ``` -------------------------------- ### Using a Custom Recommendation Algorithm Macro (PHP) Source: https://github.com/snowlaboratory/laravel-mirror/blob/main/README.md Illustrates how to use a previously defined custom algorithm macro (e.g., `huggingFace`) within the `registerRecommendations` method of a model. This simplifies the recommendation strategy definition. ```php // Model.php class User extends Model { public function registerRecommendations(): void { $this->registerStrategy(User::class) ->euclidean('follewers') ->huggingFace('activity') ->levenshtein('bio'); } } ``` -------------------------------- ### Register Basic Recommendation Strategy (Levenshtein) Source: https://github.com/snowlaboratory/laravel-mirror/blob/main/README.md Registers a recommendation strategy for the Post model using the Levenshtein algorithm to compare the 'title' property. Requires the Recommendations trait. ```php use SnowBuilds\Mirror\Concerns\Recommendations; use SnowBuilds\Mirror\Mirror; class Post extends Model { use Recommendations; public function registerRecommendations(): void { $this->registerStrategy(Post::class) ->levenshtein('title'); } } ``` -------------------------------- ### Combine Weights with Custom Algorithms Source: https://github.com/snowlaboratory/laravel-mirror/blob/main/README.md Registers a recommendation strategy using multiple custom closures for scoring (Levenshtein on title, Euclidean on tags) and applies specific weights to each custom algorithm. ```php public function registerRecommendations(): void { $this->registerStrategy(Post::class) ->using(function ($a, $b) { return Algorithm::levenshtein($a->title, $b->title); }) ->using(function ($a, $b) { return Algorithm::euclidean($a->tags, $b->tags); }) ->weights([2,1]); } ``` -------------------------------- ### Defining a Custom Recommendation Algorithm Macro (PHP) Source: https://github.com/snowlaboratory/laravel-mirror/blob/main/README.md Shows how to define a custom recommendation algorithm as a macro on the `ScoringStrategy` class. This allows extracting complex algorithm logic into a reusable method, creating a cleaner API like `->huggingFace`. ```php // ServiceProvider.php ScoringStrategy::macro('huggingFace', function (...$args) { return $this->registerAlgorithm( fn($a, $b) => HuggingFace::invokeEmbedding($a, $b), ...$args ); }); ``` -------------------------------- ### Register Weighted Recommendation Strategy (Levenshtein & Euclidean) Source: https://github.com/snowlaboratory/laravel-mirror/blob/main/README.md Registers a recommendation strategy combining Levenshtein on 'title' (weight 2) and Euclidean on 'tags' (weight 1) to create a weighted average score. ```php public function registerRecommendations(): void { $this->registerStrategy(Post::class) ->levenshtein('title', 2) ->euclidean('tags', 1); } ``` -------------------------------- ### Defining a Morph Recommendation Relationship (PHP) Source: https://github.com/snowlaboratory/laravel-mirror/blob/main/README.md Explains how to define a polymorphic relationship to recommended content using the `morphRecommendation` trait method within a model. This allows fetching recommended items (like Recipes) directly via a model relationship, ordered by suggestion score. ```php class User extends Authenticatable { use Recommendations; public function recommendedRecipes() { return $this->morphRecommendation(Recipe::class); } } ``` -------------------------------- ### Register Custom Recommendation Algorithm Source: https://github.com/snowlaboratory/laravel-mirror/blob/main/README.md Registers a recommendation strategy for the User model using a custom closure to define the scoring algorithm, comparing user and post names with Levenshtein. ```php class User extends Model { public function registerRecommendations(): void { $this->registerStrategy(Post::class) ->using(function (User $a, Post $b) { return Algorithm::levenshtein($a->name, $b->name); }); } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.