File tree Expand file tree Collapse file tree 5 files changed +48
-0
lines changed
Expand file tree Collapse file tree 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
5454 {
5555 return $ this ->hasMany (Notification::class, "user_id " );
5656 }
57+
58+ public function favorites (): HasMany
59+ {
60+ return $ this ->hasMany (Favorite::class, "user_id " );
61+ }
5762}
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ type User {
99 updated_at : String !
1010 posts : [Post ]! @hasMany
1111 notifications : [Notification ]! @hasMany
12+ favorites : [Favorit ] @hasMany
1213}
1314
1415
@@ -57,3 +58,11 @@ type Comment {
5758 created_at : String
5859 updated_at : String
5960}
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 11extend type Query {
22 users : [User ! ]! @paginate @guard
33 user (id : ID ! @eq ): User @find
4+ myFavorites : [Favorite ]! @guard
45}
You can’t perform that action at this time.
0 commit comments