Skip to content

Commit 7744dad

Browse files
committed
Full examples for User, Role & RoleUser (pivot table)
1 parent e88eab2 commit 7744dad

File tree

1 file changed

+76
-3
lines changed

1 file changed

+76
-3
lines changed

readme.md

Lines changed: 76 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Laravel utility to keep records synced between enviroments through source contro
99

1010

1111
## Examples
12-
**User.json**:
12+
### User.json:
1313
```json
1414
[
1515
{
@@ -28,10 +28,9 @@ Laravel utility to keep records synced between enviroments through source contro
2828
]
2929
```
3030

31-
translates to:
31+
translates to...
3232

3333
```php
34-
3534
User::updateOrCreate([
3635
'email' => '[email protected]',
3736
],[
@@ -43,6 +42,80 @@ User::updateOrCreate([
4342
->first()
4443
->id,
4544
]);
45+
```
46+
47+
### Role.json:
48+
```json
49+
[
50+
{
51+
"_slug": "update-student-records"
52+
},
53+
{
54+
"_slug": "borrow-ferrari"
55+
},
56+
{
57+
"_slug": "destroy-ferrari"
58+
}
59+
]
60+
```
61+
62+
translates to...
63+
64+
```php
65+
Role::updateOrCreate(['slug' => 'update-student-records']);
66+
67+
Role::updateOrCreate(['slug' => 'borrow-ferrari']);
68+
69+
Role::updateOrCreate(['slug' => 'destroy-ferrari']);
70+
```
71+
72+
### RoleUser.json (pivot table with model):
73+
```json
74+
[
75+
{
76+
"_user": {
77+
"email": "[email protected]"
78+
},
79+
"_role": {
80+
"slug": "update-student-records"
81+
}
82+
},
83+
{
84+
"_user": {
85+
"email": "[email protected]"
86+
},
87+
"_role": {
88+
"slug": "borrow-ferrari"
89+
}
90+
},
91+
{
92+
"_user": {
93+
"email": "[email protected]"
94+
},
95+
"_role": {
96+
"slug": "destroy-ferrari"
97+
}
98+
}
99+
]
100+
```
101+
102+
translates to...
103+
104+
```php
105+
RoleUser::updateOrCreate([
106+
'user_id' => User::where('email', '[email protected]')->first()->id,
107+
'role_id' => Role::where('slug', 'update-student-records')->first()->id,
108+
]);
109+
110+
RoleUser::updateOrCreate([
111+
'user_id' => User::where('email', '[email protected]')->first()->id,
112+
'role_id' => Role::where('slug', 'borrow-ferrari')->first()->id,
113+
]);
114+
115+
RoleUser::updateOrCreate([
116+
'user_id' => User::where('email', '[email protected]')->first()->id,
117+
'role_id' => Role::where('slug', 'destroy-ferrari')->first()->id,
118+
]);
46119

47120
```
48121

0 commit comments

Comments
 (0)