PHP code example of aurorawebsoftware / connective
1. Go to this page and download the library: Download aurorawebsoftware/connective 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/ */
use AuroraWebSoftware\Connective\Contracts\ConnectiveContract;
use AuroraWebSoftware\Connective\Models\Connection;
use AuroraWebSoftware\Connective\Traits\Connective;
class User extends Model implements ConnectiveContract
{
use Connective
public static function supportedConnectionTypes(): array
{
return ['friendship', 'parentage'];
}
// implementation of the model
}
use AuroraWebSoftware\Connective\Contracts\ConnectiveContract;
use AuroraWebSoftware\Connective\Models\Connection;
use AuroraWebSoftware\Connective\Traits\Connective;
class Address extends Model implements ConnectiveContract
{
use Connective
public static function supportedConnectionTypes(): array
{
return ['home', 'office'];
}
// implementation of the model
}
$connections = $user1->connections('friendship');
// Retrieve all connections for the user
$connections = $user->connections();
// $connections is a collection of Connection models
$residences = $user->connectives(['residence', 'office'], Address::class);
// $residences is a collection of Address models (residences and offices addresses of the user)
$user = User::find(1);
// Retrieve friends of friends (nested connections)
$friendsOfFriends = $user->connectives('friend')->connectives('friend');
// $friendsOfFriends is a collection of User models (friends of friends)
$user = User::find(1);
// Retrieve a more complex nested connection
$complexNestedConnections = $user->connectives('friend')->connectives('residence')->connectives('collaborator');
// $complexNestedConnections is a collection of models based on the specified nested connections