PHP code example of patinthehat / laravel-dynamic-relations
1. Go to this page and download the library: Download patinthehat/laravel-dynamic-relations 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/ */
patinthehat / laravel-dynamic-relations example snippets
$prop = "myProp";
$user->$prop->toArray();
namespace App\Models;
use Permafrost\DynamicRelations\DynamicModel;
class User extends DynamicModel
{
public static $dynamicRelations = [
'abc', 'def',
];
public function abc()
{
return $this->hasMany('App\Models\Abc');
}
public function def()
{
return $this->hasMany('App\Models\Def');
}
}
$user = User::find(1);
$prop = "abc";
$user->$prop->toArray();