I've 2 tables: courses: id, name, category_id and categories: id, name I wanted to define dynamic models for them along with dynamic relation. For this I've defined 3rd table that stores the meta(fields, foreign key) of above 2 tables. So far I've written following code:
$entity = Entity::with(['fields'])->find(1);
$model = new CurrentEntity();
$model->setTable($entity->db_key);
foreach($entity->fields as $field)
{
if($field->data_source == 'DATABASE')
{
$relatedModel = new RelatedEntity();
$relatedModel->setTable($field->reference);
$model->setRelation('categories', $relatedModel);
}
}
I could set table for CurrentEntity and get data for it. But I'm unable to set relation and get the data from related table.
How could I achieve the solution?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire