1. Go to this page and download the library: Download tusimo/embed-relation 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/ */
tusimo / embed-relation example snippets
class User extends Model {
use \Tusimo\Eloquent\Traits\EmbedsRelation;
use \Tusimo\Eloquent\Traits\CastAttributes;
protected $virtualColumnMaps = [
'data' => [
'address' => 'home_address',//you can rename the column
'follower_ids'
],
//'more_json_data' => [],
];
protected $casts = [
'book_ids' => 'integer_array',
'home_address' => 'string',
'follower_ids' => 'integer_array',
];
...
}
class User extends Model {
use \Tusimo\Eloquent\Traits\EmbedsRelation;
public function books () {
return $this->embedsMany(Book::class);
}
}
$user->home_address = 'HA';
$user->follower_ids = [1,2,3,4];
$user->save();
foreach($user->follower_ids as $followerId) {//which now is array type
echo $followerId;
}
if($user->isVirtualDirty('home_address')) {
//detect virtual column is dirty or not
dd($user->getVirtualDirty());
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.