PHPackages                             netflex/database - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. netflex/database

ActiveLibrary[Database &amp; ORM](/categories/database)

netflex/database
================

Netflex Database driver for Laravel

v2.0.0(2y ago)0151MITPHPPHP ^8.1

Since Mar 17Pushed 2y agoCompare

[ Source](https://github.com/netflex-sdk/database)[ Packagist](https://packagist.org/packages/netflex/database)[ RSS](/packages/netflex-database/feed)WikiDiscussions 1.x Synced 1mo ago

READMEChangelog (6)Dependencies (6)Versions (8)Used By (0)

Netflex Database Driver for Laravel
===================================

[](#netflex-database-driver-for-laravel)

[![Build Status](https://github.com/netflex-sdk/database/actions/workflows/static_analysis.yml/badge.svg)](https://github.com/netflex-sdk/database/actions)[![Total Downloads](https://camo.githubusercontent.com/97f841d1bafad51dc24b43e5507db4643c61f1102c1ad0ae5dcd11810f57a415/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6e6574666c65782f6461746162617365)](https://packagist.org/packages/netflex/database)[![Latest Stable Version](https://camo.githubusercontent.com/cca7a3bdba29a3740db0caa85fd4b0a36fab0cdc29ccbb5b80ce43d272f1baf9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e6574666c65782f6461746162617365)](https://packagist.org/packages/netflex/database)[![License](https://camo.githubusercontent.com/103ed01eb923c6a57fb3e8ac955eab3ce1dc8a0d2408b46b45d7b45619c635fa/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6e6574666c65782f6461746162617365)](https://packagist.org/packages/netflex/database)

This package provides a database driver for Laravel that enables you to use the Netflex API as a database backend for your Laravel application.

This package supports Laravel 8 through 10, and PHP 7.4 through 8.2.

Table of contents
-----------------

[](#table-of-contents)

- [Motivation / Why?](#motivation--why)
    - [Installation](#installation)
    - [Usage](#usage)
        - [Configuration](#configuration)
- [Eloquent](#eloquent)
    - [Reference Model](#reference-model)
    - [Models](#models)
        - [Caveats](#caveats)
- [Migrations](#migrations)
- [Netflex specific functionality](#netflex-specific-functionality)
    - [Caching](#caching)
    - [Automatically respecting the publishing status of an entry](#automatically-respecting-the-publishing-status-of-an-entry)
    - [Refresh data from API on save](#refresh-data-from-api-on-save)
    - [Automatically setting name of entries](#automatically-setting-name-of-entries)
- [Limitations](#limitations)
- [Todo](#todo)
- [License](#license)

Motivation / Why?
-----------------

[](#motivation--why)

Laravel provides a powerful database abstraction layer that allows you to use a variety of different database backends.

Most first and third party packages in the Laravel ecosystem assumes that you are using a relational database backend.

This package enables you to use the Netflex API as a database backend for your Laravel application, bridging the gap between the Netflex API and Laravel.

This enables you to use most of Laravels functionality out of the box, while still using the Netflex API as your backend.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require netflex/database
```

Usage
-----

[](#usage)

### Configuration

[](#configuration)

Add the following to your `config/database.php` file:

```
return [
    'connections' => [

        'netflex' => [
            'driver' => 'netflex',
            'adapter' => 'entry',
        ]
    ]
];
```

Note that the `adapter` property is required if you want to be able to perform "write" operations, and must be set to a valid adapter name. The following adapters are currently supported:

- `entry` (Full support)
- `customer` (Write support, schema manipulation not supported due to API limitations)
- `page` (Read-only support)
- `read-only` (also aliased as `default` for fallback purposes)

If no adapter is specified, the connection will only work as a read-only connection, and you won't be able to interrogate your connections Schema or perform any write operations.

Note that by using the `entry` adapter, your models `$prefix` property will be prepended with `entry_` to match the Netflex index naming convention.

You may also provide a custom adapter class. It needs to implement the `Netflex\Database\DBAL\Contracts\DatabaseAdapter` interface.

The adapter is responsible for translating betweeen the database layer of Laravel and the Netflex API.

#### Advanced configuration

[](#advanced-configuration)

##### Using different API connections

[](#using-different-api-connections)

If you have multiple API connections configured, you can specify which one to use by setting the `connection` property on the connection configuration. (See [netflex/api](https://github.com/netflex-sdk/api/blob/master/config/api.php) for reference).

```
[
    'driver' => 'netflex',
    'adapter' => 'entry',
    'connection' => 'my-connection' // Refers to a Netflex API connection
]
```

Eloquent
--------

[](#eloquent)

### Refrence Model

[](#refrence-model)

This package provides a reference model that you can use as a base for your models. This is recommended for most use cases, as it provides a number of useful features.

```
namespace App\Models;

use Netflex\Database\Eloquent\Model;

class Article extends Model
{
    //
}
```

### Models

[](#models)

To use the Netflex API as a database backend for your Eloquent models, all you have to do is register a database connection that use the `netflex` driver.

If you have configured aliases for your Netflex structures, you can skip name `$table` property and let Eloquent resolve the index name for you based on the models alias.

If creating structures through Laravel migrations and using the `entry` adapter, we will automatically add a table alias for you. This alias follows the convention of the pluralized model name in snake\_case.

Example:

In the following example, a default database connection is configured with the name `structures` to use the `netflex` driver, and the `entry` adapter.

`config/database.php`

```
return [
    'default' => 'structures',

    'connections' => [

        'structures' => [
            'driver' => 'netflex',
            'adapter' => 'entry',
        ]
    ]
];
```

```
