PHP code example of rob-lester-jr04 / call-forwarding

1. Go to this page and download the library: Download rob-lester-jr04/call-forwarding library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

rob-lester-jr04 / call-forwarding example snippets


namespace App\Models;

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

class PageVisit extends Model implements ShouldForward
{
	
	use ReceivesCalls;
	
}


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

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


$model = new PageVisit;

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



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

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



namespace App\Handlers; // or whatever namespace you want to use

use Lester\Forwarding\Contracts\CallForwardingDriver;
use Illuminate\Support\Collection;

class MyHandler implements CallForwardingDriver
{
	// Worth noting, $key is only ever 'update' or 'insert'
	public function putItem($key, $data): void
	{
		// Store the db write.
	}
	
	public function getAllItems($key, $purge = false): Collection
	{
		// Retrieve the collection of stored db writes
		
		// Purge each item if the $purge flag is true.
	}
}

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