Skip to content

Commit

Permalink
docs updated
Browse files Browse the repository at this point in the history
  • Loading branch information
kriit24 committed Dec 9, 2023
1 parent 45a7fc9 commit 98f16ae
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 9 deletions.
19 changes: 13 additions & 6 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

72 changes: 72 additions & 0 deletions src/docs/rest_api/Insert_relational_data.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
### INSERT RELATIONAL DATA

setup relational parent table

```
//App\Models\objectT.php - set relation after inserted
protected $dispatchesEvents = [
'inserted' => ObjectAfterInsert::class,
];
//App\Models\Event\ObjectAfterInsert.php - call relation
declare(strict_types=1);
namespace App\Models\Events;
use App\Models\objectT;
class ObjectAfterInsert extends objectT
{
public function __construct($bindings, $tableData)
{
new TableRelation($this->getTable(), $this->getKeyName(), $bindings, $tableData);
}
}
```

setup relational child table

```
//App\Models\address.php - set relation before insert
protected $dispatchesEvents = [
'inserting' => AddressBeforeInsert::class,
];
//App\Models\Events\AddressBeforeInsert.php - get relation id
declare(strict_types=1);
namespace App\Models\Events;
class AddressBeforeInsert
{
public function __construct(&$bindings)
{
if (isset($bindings['table_relation_unique_id'])) {
$relation = TableRelation::fetch($bindings['table_relation_unique_id']);
if( !empty($relation) ) {
//die(pre($relation));
$bindings['image_table'] = $relation->table_relation_table_name;
$bindings['image_table_id'] = $relation->table_relation_table_id;
}
}
}
}
```

use it on react native app

```
let object_unique_id = object.insert({
'object_name': 'this is object name',
});
address.insert({
'table_relation_unique_id': object_unique_id,//by that unique id two tables are merged in laravel
'address_name': 'this is address name',
});
```
5 changes: 5 additions & 0 deletions src/docs/rest_api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,8 @@ react-native request will be - https://your_domain.com/fetch/{database_name_wher

debug query - when u send request to laravel api with header "debug=true" then it shows mysql query not data



### SEE MORE DOCS

[Insert relational data](/Insert_relational_data.md)
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ public function __construct(&$bindings)
if (isset($bindings['table_relation_unique_id'])) {

$relation = TableRelation::fetch($bindings['table_relation_unique_id']);
//die(pre($relation));
$bindings['image_table'] = $relation->table_relation_table_name;
$bindings['image_table_id'] = $relation->table_relation_table_id;
if( !empty($relation) ) {

//die(pre($relation));
$bindings['image_table'] = $relation->table_relation_table_name;
$bindings['image_table_id'] = $relation->table_relation_table_id;
}
}
}
}

0 comments on commit 98f16ae

Please sign in to comment.