2020-06-26 23:32:33 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Support\Facades\Auth;
|
2020-10-21 00:29:50 +00:00
|
|
|
use App\Http\Requests\NewCommentRequest;
|
|
|
|
|
|
|
|
use App\Comment;
|
|
|
|
use App\Application;
|
|
|
|
use App\Notifications\NewComment;
|
|
|
|
use App\User;
|
2020-06-26 23:32:33 +00:00
|
|
|
|
|
|
|
class CommentController extends Controller
|
|
|
|
{
|
2020-10-21 00:29:50 +00:00
|
|
|
|
2020-06-26 23:32:33 +00:00
|
|
|
public function index()
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
public function insert(NewCommentRequest $request, Application $application)
|
|
|
|
{
|
2020-06-27 18:15:33 +00:00
|
|
|
$this->authorize('create', Comment::class);
|
2020-07-16 20:21:28 +00:00
|
|
|
|
2020-06-26 23:32:33 +00:00
|
|
|
$comment = Comment::create([
|
|
|
|
'authorID' => Auth::user()->id,
|
|
|
|
'applicationID' => $application->id,
|
2020-10-21 00:29:50 +00:00
|
|
|
'text' => $request->comment
|
2020-06-26 23:32:33 +00:00
|
|
|
]);
|
|
|
|
|
2020-10-21 00:29:50 +00:00
|
|
|
if ($comment)
|
|
|
|
{
|
|
|
|
|
2020-06-26 23:32:33 +00:00
|
|
|
$request->session()->flash('success', 'Comment posted! (:');
|
2020-10-21 00:29:50 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-06-26 23:32:33 +00:00
|
|
|
$request->session()->flash('error', 'Something went wrong while posting your comment!');
|
|
|
|
}
|
|
|
|
|
|
|
|
return redirect()->back();
|
2020-10-21 00:29:50 +00:00
|
|
|
|
2020-06-26 23:32:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function delete(Request $request, Comment $comment)
|
|
|
|
{
|
2020-06-27 18:15:33 +00:00
|
|
|
$this->authorize('delete', $comment);
|
2020-06-26 23:32:33 +00:00
|
|
|
|
2020-06-27 18:15:33 +00:00
|
|
|
$comment->delete();
|
|
|
|
$request->session()->flash('success', 'Comment deleted!');
|
2020-06-26 23:32:33 +00:00
|
|
|
|
|
|
|
return redirect()->back();
|
2020-10-21 00:29:50 +00:00
|
|
|
|
2020-06-26 23:32:33 +00:00
|
|
|
}
|
2020-10-21 00:29:50 +00:00
|
|
|
|
2020-06-26 23:32:33 +00:00
|
|
|
}
|