Skip to content

Commit 9423e4e

Browse files
committed
wip
1 parent 1e43f20 commit 9423e4e

File tree

3 files changed

+76
-1
lines changed

3 files changed

+76
-1
lines changed

docs/docs/3.0/auth/profile.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,76 @@ Binaryk\LaravelRestify\Http\Requests\ProfileAvatarRequest::usingPath(function(Il
7070
})
7171
```
7272

73+
74+
## Profile via User Repository
75+
76+
You can use the `UserRepository` (if you have one), to resolve the profile and perform the updates over the profile by using the `UserProfile` trait in your repository:
77+
78+
```php
79+
class UserRepository extends Repository
80+
{
81+
use Binaryk\LaravelRestify\Repositories\UserProfile;
82+
}
83+
```
84+
85+
Now you can inform whatever the Restify can use this repository to return the profile:
86+
87+
```php
88+
public static $canUseForProfile = true;
89+
```
90+
91+
or to update it:
92+
93+
```php
94+
public static $canUseForProfileUpdate = true;
95+
```
96+
97+
If the `UserRepository` is used to get the user profile, the format of the data will follow the JSON:API format:
98+
99+
```json
100+
{
101+
"id": "1"
102+
"type": "users"
103+
"attributes": {
104+
"name": "Eduard Lupacescu"
105+
"email": "[email protected]"
106+
"password": ""
107+
}
108+
}
109+
```
110+
111+
You can specify related entities as for an usual request:
112+
113+
```http request
114+
GET: restify-api/profile?related=posts
115+
```
116+
117+
So Restify will attach the relationships to the response:
118+
119+
```json
120+
{
121+
"id": "1"
122+
"type": "users"
123+
"attributes": {
124+
"name": "Eduard Lupacescu"
125+
"email": "[email protected]"
126+
}
127+
"relationships": {
128+
"posts": array:1 [
129+
0 => {
130+
"attributes": {
131+
"id": 1
132+
"user_id": "1"
133+
134+
```
135+
136+
If you want to attach some custom / meta profile data, you can do that by overriding the:
137+
138+
139+
```php
140+
// UserRepository
141+
public static function metaProfile(Request $request): array
142+
{
143+
return static::$metaProfile;
144+
}
145+
```

docs/docs/3.0/repository-pattern/repository-pattern.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ use Binaryk\LaravelRestify\Controllers\RestController;
454454
class PostController extends RestController
455455
{
456456
/**
457-
* Show the profile for the given user.
457+
* Show the kpi for the given user.
458458
*
459459
* @param int $id
460460
* @return JsonResponse

tests/Fixtures/User/UserRepository.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ class UserRepository extends Repository
1515
{
1616
use UserProfile;
1717

18+
public static $canUseForProfile = true;
19+
1820
public static $model = User::class;
1921

2022
public static $search = [

0 commit comments

Comments
 (0)