We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 42b348a commit 7855cb9Copy full SHA for 7855cb9
app/GraphQL/Mutations/CreateComment.php
@@ -0,0 +1,28 @@
1
+<?php
2
+
3
+namespace App\GraphQL\Mutations;
4
5
+use App\Models\Comment;
6
+use Error;
7
+use Illuminate\Support\Facades\Auth;
8
9
+final class CreateComment
10
+{
11
+ /**
12
+ * @param array{} $args
13
+ */
14
+ public function __invoke($_, array $args)
15
+ {
16
+ $quard = Auth::guard("api");
17
+ if (!$quard->user()) {
18
+ throw new Error("Invalid credentials.");
19
+ }
20
+ $user = $quard->user();
21
22
+ $comment = Comment::create([
23
+ "content" => $args["content"],
24
+ "author_id" => $user->id
25
+ ]);
26
+ return $comment;
27
28
+}
0 commit comments