Skip to content

Commit 7855cb9

Browse files
committed
create comment
1 parent 42b348a commit 7855cb9

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)