Download the PHP package drderpling/eloquent-directus-repository without Composer

On this page you can find all versions of the php package drderpling/eloquent-directus-repository. 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 eloquent-directus-repository

Directus Eloquent Repository

This package implements a repository pattern that enables the lazy loading of data from Directus into Eloquent models within a Laravel application.

Requirements

Installation

Usage

Create a New Repository

To create a new repository, extend the EloquentDirectusRepository in a new class and implement the getContext() method to return a configured Context object. This object specifies the model and fields to be loaded.

Example of a basic repository setup:

`

Context Object

In order for the repository to know which model to load we need to provide a context. The context is an object that defines the model that should be loaded. This object is created using the ContextFactory::create() method. This method takes the model class as a parameter.

Options

The ContextFactory::create() method has 4 parameters. Ill break down each parameter below:

Options for ContextFactory::create()

Parameter Description
$modelClass The class of the model to be loaded. Required.
$fields An array of fields to be loaded. If empty, all fields will be loaded. Optional.
$collectionName The name of the collection to be loaded. If empty, the repository will generate the collection name based on the model class. Optional.
$orderBy The field used to order the records. If empty, the repository will use the sort field. Setting this to null disables ordering. Optional.

Adding the $fillable property to the model

In order for the repository to be able to save data to the database, the model must have a $fillable property. This property should be an array of fields that are allowed to be mass assigned. This is a security feature to prevent unwanted fields from being saved to the database.

For more information on the $fillable property, see the Laravel documentation: https://laravel.com/docs/11.x/eloquent#mass-assignment

Methods

getList()

To get a list of records, you can call the getList() method. This will return a collection of records. similar to the all() method in eloquent.

get()

To get a single record, you can call the get() method with the id of the record you want to load. This will return a single record. This id is the id from your own database, not the directus id. See get getByCmsId for information on loading by directus id.

getByCmsId()

To get a single record by the directus id, you can call the getByCmsId() method with the id of the record you want to load. This will return a single record. The id provide is the one from directus, not your own database id. See get id for more information.

Advanced Usage

In some scenarios, you may need to load data from multiple collections or perform some preprocessing on the data before it is saved to the database. This section explains how to customize the data handling process by overriding specific methods in your repository.

Preparing Data

The prepareData() method is called before data is saved to the database. This method provides an opportunity to manipulate the data array and should return a Laravel Collection containing the prepared data.

For instance, when loading a Project model along with associated Skills, you may need to process the skills and append them to the main data array:

In the above example, skills data is processed and structured to be compatible with the Project model before being saved.

Model Creation or Update

The updateOrCreate() method is used to create or update a model instance based on the provided data. This method can be overridden to include custom logic for handling complex relationships or additional fields that are not directly part of the main model.

Here's how you can handle complex data relationships, like attaching skills to a project:

In this example, after updating or creating the Project model, associated Skills are processed and attached using the attach method of Laravel's Eloquent relationships. This ensures that the project's skills are updated in sync with changes from Directus.

These advanced methods offer flexibility and robustness in your repository, allowing for complex data interactions that are common in real-world applications.


All versions of eloquent-directus-repository with dependencies

PHP Build Version
Package Version
No informations.
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 drderpling/eloquent-directus-repository contains the following files

Loading the files please wait ....