53 lines
1.3 KiB
PHP
53 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use App\WorkflowDocument;
|
|
use App\Comment;
|
|
use App\Setting;
|
|
use Validator;
|
|
use Session;
|
|
|
|
class CommentsController extends Controller
|
|
{
|
|
|
|
public function index(Request $request, $id)
|
|
{
|
|
$id=base64_decode($id);
|
|
$workflow_document = WorkflowDocument::findOrFail($id);
|
|
$setting = Setting::first();
|
|
$comments = Comment::where('workflow_document_id', $workflow_document->id)->get();
|
|
|
|
|
|
return $comments;
|
|
}
|
|
|
|
public function store(Request $request)
|
|
{
|
|
$validate = $this->rules();
|
|
|
|
if($validate->fails())
|
|
return back()->withErrors($validate)->withInput();
|
|
|
|
$document = WorkflowDocument::findOrFail($request->workflow_document_id);
|
|
|
|
$comment = new Comment($validate->valid());
|
|
$comment->comment = nl2br($request->input('comment'));
|
|
$comment->user_id = auth()->user()->id;
|
|
$comment->save();
|
|
|
|
Session::flash('success_message', __('Comment created.'));
|
|
return redirect()->route('details',base64_encode($document->id))->withInput(['tab'=>$request->tab]);
|
|
}
|
|
|
|
private function rules()
|
|
{
|
|
return Validator::make(request()->all(), [
|
|
'workflow_document_id' => 'required',
|
|
'comment' => 'required',
|
|
]);
|
|
}
|
|
|
|
}
|