Download the PHP package vlados/laravel-related-content without Composer

On this page you can find all versions of the php package vlados/laravel-related-content. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-related-content

Laravel Related Content

Build related content links using vector embeddings and pgvector for Laravel.

Latest Version on Packagist

Features

Requirements

Installation

1. Install pgvector extension in PostgreSQL

The migration runs this automatically, but CREATE EXTENSION requires a privileged database user. On managed Postgres (RDS, Cloud SQL, Supabase, etc.) enable the extension up front — as shown above or via the provider's dashboard — so the migration only needs to create the tables.

2. Install the package via Composer

3. Publish the config and migrations

4. Configure your environment

Usage

1. Add the trait to your models

2. Configure models for cross-model relationships

In config/related-content.php:

3. Related content is automatically synced on save

4. Retrieve related content

getRelatedModels() and getRelatedOfType() are the complete views — they merge both directions (where this model is the source or the related target). The raw relatedContent() relation returns only the rows where this model is the source; because each pair is stored once (and refreshed on re-sync), prefer the helper methods when you want the full set.

5. Use in Blade templates

Artisan Commands

Rebuild embeddings and related content

Semantic Search

You can also use the package for semantic search:

Configuration

Embedding dimensions

The active provider's dimensions value is the single source of truth. It sizes the vector column when the migration runs and determines the length of every stored vector, so the two can never drift. The top-level dimensions key is only a fallback used when the active provider does not define its own.

Because the column width is fixed at migration time, changing the effective dimension count (or switching to a provider with a different one) requires a fresh migration of the embeddings table — re-run related-content:rebuild afterwards to regenerate the vectors.

Disabling

Set RELATED_CONTENT_ENABLED=false (or leave the provider's credentials empty) and the package degrades gracefully: no jobs are dispatched and no embeddings are written, so existing rows are left untouched.

Events

The package dispatches events you can listen to:

How It Works

  1. On Model Save: When a model with HasRelatedContent is saved, a job is dispatched
  2. Generate Embedding: The job generates a vector embedding from the model's embeddable fields
  3. Find Similar: Uses pgvector to find similar content across all configured models
  4. Store Links: Stores the related content relationships in the related_content table
  5. Fast Retrieval: When displaying related content, it's a simple database lookup (no API calls)

Bidirectional Relationships

Related content works in both directions automatically. When a new BlogPost is saved and finds an Event as related, the Event will also show the BlogPost in its related content - without needing to re-sync the Event.

This is achieved by querying both directions:

Results are deduplicated and sorted by similarity score.

When a model is re-synced (its embeddable content changed), every link incident to it is rebuilt in both directions, so similarity scores never go stale. Links to models that are no longer mutually similar are rebuilt on their own next sync, or run related-content:rebuild --force to refresh the whole graph at once.

Search accuracy at scale

The embeddings table uses an HNSW index, which performs approximate nearest -neighbour search. When you mix several model types and filter by type (or by the similarity threshold), pgvector may occasionally return fewer than max_related_items candidates because the type filter is applied after the index narrows the search. If you rely on cross-model results over a large dataset, raise hnsw.ef_search for the session or consider pgvector 0.8+ iterative index scans.

Performance

License

MIT License. See LICENSE for more information.

Credits


All versions of laravel-related-content with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
spatie/laravel-package-tools Version ^1.16
illuminate/contracts Version ^11.0||^12.0||^13.0
pgvector/pgvector Version ^0.2
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package vlados/laravel-related-content contains the following files

Loading the files please wait ...