PHPackages                             rob-lester-jr04/call-forwarding - 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. rob-lester-jr04/call-forwarding

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

rob-lester-jr04/call-forwarding
===============================

A methodology that will reduce database writes and improve inbound request handling

1.0.3(2y ago)05MITPHP

Since Apr 15Pushed 2y ago1 watchersCompare

[ Source](https://github.com/roblesterjr04/CallForwarding)[ Packagist](https://packagist.org/packages/rob-lester-jr04/call-forwarding)[ RSS](/packages/rob-lester-jr04-call-forwarding/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (5)Versions (5)Used By (0)

Laravel Call Forwarding
=======================

[](#laravel-call-forwarding)

[![Latest Version on Packagist](https://camo.githubusercontent.com/82946cf4df07cda51a61380de426e6d6177d7df67e864d13c4297c1d070825b9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f726f622d6c65737465722d6a7230342f63616c6c2d666f7277617264696e672e737667)](https://packagist.org/packages/rob-lester-jr04/call-forwarding)[![PHP Composer](https://github.com/roblesterjr04/CallForwarding/actions/workflows/test-suite.yml/badge.svg)](https://github.com/roblesterjr04/CallForwarding/actions/workflows/test-suite.yml)[![Total Downloads](https://camo.githubusercontent.com/af6602bceb169b3fd7718a306cbd3dcd28db260f7a415c5fb3b6954ce03b3f71/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f726f622d6c65737465722d6a7230342f63616c6c2d666f7277617264696e672e737667)](https://packagist.org/packages/rob-lester-jr04/call-forwarding)

Our innovative "CallForwarding" package optimizes database performance during high-traffic scenarios by intelligently queuing up database writes on eloquent models. By consolidating these writes into a single operation, it alleviates strain on database resources, ensuring smooth operations even during peak times. With ForwardSync, your system gains efficiency and resilience, allowing you to focus on delivering exceptional user experiences without worrying about database constraints.

Table of Contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Usage](#usage)
- [Support](#support)
- [Contributing](#contributing)

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

[](#installation)

Download to your project directory, add `README.md`, and commit:

```
composer require rob-lester-jr04/call-forwarding
```

Usage
-----

[](#usage)

For each model you want to implement call forwarding on, include both the trait and the interface.

```
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Lester\Forwarding\ReceivesCalls;
use Lester\Forwarding\ShouldForward;

class PageVisit extends Model implements ShouldForward
{

	use ReceivesCalls;

}
```

Then, to make an update or an insert, call `callForwarding()` before your persist method. Example:

```
$visit = new PageVisit;
$visit->hits = 15;

$visit-> forwarded()->save(); // This will return false. That is expected.
```

Now by default, every minute, anything that has been queued this way will get persisted.

Advanced Configuration
----------------------

[](#advanced-configuration)

### Changing the driver

[](#changing-the-driver)

The package is built in with 3 drivers for the queue. The default is `file`, but it also includes `redis` and `memcached`.

Your choices out of the box are File or Redis. To use the Redis option, add this to your `.env` file:

```
CF_DRIVER=redis
```

### Write Callbacks

[](#write-callbacks)

If you have code you'd like to execute after the write has occured, you can chain the `afterForward` method with a closure as the parameter. Example.

```
$model = new PageVisit;

$visit->afterForward(function($attrs) {
	// Do something else with the attributes.
})->forwarded()->save();
```

### Publishing the config file.

[](#publishing-the-config-file)

```
php artisan vendor:publish --provider="Lester\Forwarding\CallForwardingServiceProvider"
```

### Custom Driver

[](#custom-driver)

Too generate your own driver, create a class that implements the `CallForwardingDriver` interface with the following methods: `putItem`, `getAllItems`

Register the custom class in the config file under the handler array and use the slug you defined as the handler.

```
'handler' => 'my-custom-handler',

'handlers' => [
	// ...
	'my-custom-handler' => \App\My\Handler::class,
],
```

```
