1
0
Fork 1
mirror of https://github.com/pixelfed/pixelfed.git synced 2024-12-25 17:26:43 +00:00
pixelfed/app/Http/Controllers/CommentController.php

45 lines
1.1 KiB
PHP
Raw Normal View History

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Jobs\StatusPipeline\NewStatusPipeline;
use Auth, Hashids;
use App\{Comment, Profile, Status};
class CommentController extends Controller
{
public function store(Request $request)
{
if(Auth::check() === false) { abort(403); }
$this->validate($request, [
'item' => 'required|integer',
'comment' => 'required|string|max:500'
]);
$comment = $request->input('comment');
$statusId = $request->item;
$user = Auth::user();
$profile = $user->profile;
$status = Status::findOrFail($statusId);
$reply = new Status();
$reply->profile_id = $profile->id;
$reply->caption = $comment;
2018-06-01 18:33:44 +00:00
$reply->rendered = e($comment);
$reply->in_reply_to_id = $status->id;
$reply->in_reply_to_profile_id = $status->profile_id;
$reply->save();
NewStatusPipeline::dispatch($reply, false);
2018-06-01 02:37:11 +00:00
if($request->ajax()) {
$response = ['code' => 200, 'msg' => 'Comment saved'];
} else {
$response = redirect($status->url());
}
return $response;
}
}