File tree 5 files changed +48
-0
lines changed
5 files changed +48
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace App \GraphQL \Queries ;
4
+
5
+ use Error ;
6
+ use Illuminate \Support \Facades \Auth ;
7
+
8
+ final class MyFavorites
9
+ {
10
+ /**
11
+ * @param array{} $args
12
+ */
13
+ public function __invoke ($ _ , array $ args )
14
+ {
15
+ $ quard = Auth::guard ("api " );
16
+ if (!$ quard ->user ()){
17
+ throw new Error ("Invalid credentials. " );
18
+ }
19
+ $ user = $ quard ->user ();
20
+ return $ user ->favorites ;
21
+ }
22
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace App \Models ;
4
+
5
+ use Illuminate \Database \Eloquent \Factories \HasFactory ;
6
+ use Illuminate \Database \Eloquent \Model ;
7
+
8
+ class Favorite extends Model
9
+ {
10
+ use HasFactory;
11
+ }
Original file line number Diff line number Diff line change @@ -54,4 +54,9 @@ public function notifications(): HasMany
54
54
{
55
55
return $ this ->hasMany (Notification::class, "user_id " );
56
56
}
57
+
58
+ public function favorites (): HasMany
59
+ {
60
+ return $ this ->hasMany (Favorite::class, "user_id " );
61
+ }
57
62
}
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ type User {
9
9
updated_at : String !
10
10
posts : [Post ]! @hasMany
11
11
notifications : [Notification ]! @hasMany
12
+ favorites : [Favorit ] @hasMany
12
13
}
13
14
14
15
@@ -57,3 +58,11 @@ type Comment {
57
58
created_at : String
58
59
updated_at : String
59
60
}
61
+
62
+ type Favorite {
63
+ id : ID !
64
+ user : User ! @belongsTo
65
+ post : Post !
66
+ created_at : String
67
+ updated_at : String
68
+ }
Original file line number Diff line number Diff line change 1
1
extend type Query {
2
2
users : [User ! ]! @paginate @guard
3
3
user (id : ID ! @eq ): User @find
4
+ myFavorites : [Favorite ]! @guard
4
5
}
You can’t perform that action at this time.
0 commit comments