1. Go to this page and download the library: Download friendsofhyperf/compoships 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/ */
friendsofhyperf / compoships example snippets
namespace App;
use Hyperf\Database\Model\Model;
class User extends Model
{
public function tasks()
{
//WON'T WORK WITH EAGER LOADING!!!
return $this->hasMany(Task::class)->where('team_id', $this->team_id);
}
}
namespace App;
use Hyperf\Database\Model\Model;
class A extends Model
{
use \FriendsOfHyperf\Compoships\Compoships;
public function b()
{
return $this->hasMany('B', ['foreignKey1', 'foreignKey2'], ['localKey1', 'localKey2']);
}
}
namespace App;
use Hyperf\Database\Model\Model;
class B extends Model
{
use \FriendsOfHyperf\Compoships\Compoships;
public function a()
{
return $this->belongsTo('A', ['foreignKey1', 'foreignKey2'], ['ownerKey1', 'ownerKey2']);
}
}
namespace App;
use Hyperf\Database\Model\Model;
class User extends Model
{
use \FriendsOfHyperf\Compoships\Compoships;
public function tasks()
{
return $this->hasMany(Task::class, ['team_id', 'category_id'], ['team_id', 'category_id']);
}
}
namespace App;
use Hyperf\Database\Model\Model;
class Task extends Model
{
use \FriendsOfHyperf\Compoships\Compoships;
public function user()
{
return $this->belongsTo(User::class, ['team_id', 'category_id'], ['team_id', 'category_id']);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.