CommentController.php 1002 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use App\Jobs\StatusPipeline\NewStatusPipeline;
  5. use Auth, Hashids;
  6. use App\{Comment, Profile, Status};
  7. class CommentController extends Controller
  8. {
  9. public function store(Request $request)
  10. {
  11. if(Auth::check() === false) { abort(403); }
  12. $this->validate($request, [
  13. 'item' => 'required|integer',
  14. 'comment' => 'required|string|max:500'
  15. ]);
  16. $comment = $request->input('comment');
  17. $statusId = $request->item;
  18. $user = Auth::user();
  19. $profile = $user->profile;
  20. $status = Status::findOrFail($statusId);
  21. $reply = new Status();
  22. $reply->profile_id = $profile->id;
  23. $reply->caption = $comment;
  24. $reply->rendered = $comment;
  25. $reply->in_reply_to_id = $status->id;
  26. $reply->in_reply_to_profile_id = $status->profile_id;
  27. $reply->save();
  28. NewStatusPipeline::dispatch($reply, false);
  29. return redirect($status->url());
  30. }
  31. }