2018-04-19 05:55:58 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
2018-06-04 08:16:33 +00:00
|
|
|
use App\Jobs\CommentPipeline\CommentPipeline;
|
2018-05-26 22:46:07 +00:00
|
|
|
use App\Jobs\StatusPipeline\NewStatusPipeline;
|
|
|
|
use Auth, Hashids;
|
2018-04-19 05:55:58 +00:00
|
|
|
use App\{Comment, Profile, Status};
|
|
|
|
|
|
|
|
class CommentController extends Controller
|
|
|
|
{
|
2018-06-04 02:20:12 +00:00
|
|
|
|
2018-06-04 06:07:40 +00:00
|
|
|
public function show(Request $request, $username, int $id, int $cid)
|
2018-06-04 02:20:12 +00:00
|
|
|
{
|
|
|
|
$user = Profile::whereUsername($username)->firstOrFail();
|
2018-06-04 06:07:40 +00:00
|
|
|
$status = Status::whereProfileId($user->id)->whereInReplyToId($id)->findOrFail($cid);
|
2018-06-04 02:20:12 +00:00
|
|
|
return view('status.reply', compact('user', 'status'));
|
|
|
|
}
|
|
|
|
|
2018-08-10 02:04:48 +00:00
|
|
|
public function showAll(Request $request, $username, int $id)
|
|
|
|
{
|
|
|
|
$user = Profile::whereUsername($username)->firstOrFail();
|
|
|
|
$status = Status::whereProfileId($user->id)->findOrFail($id);
|
|
|
|
$replies = Status::whereInReplyToId($id)->paginate(40);
|
|
|
|
return view('status.comments', compact('user', 'status', 'replies'));
|
|
|
|
}
|
|
|
|
|
2018-04-19 05:55:58 +00:00
|
|
|
public function store(Request $request)
|
|
|
|
{
|
|
|
|
if(Auth::check() === false) { abort(403); }
|
|
|
|
$this->validate($request, [
|
2018-05-26 22:46:07 +00:00
|
|
|
'item' => 'required|integer',
|
2018-04-19 05:55:58 +00:00
|
|
|
'comment' => 'required|string|max:500'
|
|
|
|
]);
|
2018-05-26 22:46:07 +00:00
|
|
|
$comment = $request->input('comment');
|
|
|
|
$statusId = $request->item;
|
2018-04-19 05:55:58 +00:00
|
|
|
|
|
|
|
$user = Auth::user();
|
|
|
|
$profile = $user->profile;
|
|
|
|
$status = Status::findOrFail($statusId);
|
|
|
|
|
2018-05-26 22:46:07 +00:00
|
|
|
$reply = new Status();
|
|
|
|
$reply->profile_id = $profile->id;
|
2018-06-18 05:28:34 +00:00
|
|
|
$reply->caption = e($comment);
|
2018-06-14 00:54:27 +00:00
|
|
|
$reply->rendered = $comment;
|
2018-05-26 22:46:07 +00:00
|
|
|
$reply->in_reply_to_id = $status->id;
|
|
|
|
$reply->in_reply_to_profile_id = $status->profile_id;
|
|
|
|
$reply->save();
|
|
|
|
|
|
|
|
NewStatusPipeline::dispatch($reply, false);
|
2018-06-04 08:16:33 +00:00
|
|
|
CommentPipeline::dispatch($status, $reply);
|
2018-04-19 05:55:58 +00:00
|
|
|
|
2018-06-01 02:37:11 +00:00
|
|
|
if($request->ajax()) {
|
2018-06-18 05:28:34 +00:00
|
|
|
$response = ['code' => 200, 'msg' => 'Comment saved', 'username' => $profile->username, 'url' => $reply->url(), 'profile' => $profile->url(), 'comment' => $reply->caption];
|
2018-06-01 02:37:11 +00:00
|
|
|
} else {
|
|
|
|
$response = redirect($status->url());
|
|
|
|
}
|
|
|
|
|
|
|
|
return $response;
|
2018-04-19 05:55:58 +00:00
|
|
|
}
|
|
|
|
}
|