<?php

namespace App\Http\Controllers;
use Session;
use App\Models;
use Illuminate\Http\Request;

class CommentsController extends Controller
{
    public function index(){
        $user_id = \Auth::user()->id;
        $result = Models\Comment::with('projectStatus')
                    ->where('assignee_id', $user_id)
                    ->orderBy('project_id', 'DESC')
                    ->get();
        $data = [
            'page_title' => 'Projects Status List',
            'project_statuses' => $result
        ];
        return view('comments.index', $data);
    }
    public function add_comment($id){
        $result = Models\ProjectStatus::with('comments', 'project')->where('id', $id)->firstOrFail();
        // dd($result);
        $data = [
            'page_title' => 'Projects Status Comment',
            'project_arr' => $result
        ];
        // dump($data);
        return view('comments.create', $data);
    }
    public function store(Request $request) {
        // Save a new post
        $this->validate($request, [
            'description' => 'required',
            'status' => 'required',
            'project_id' => 'required',
            'assignee_id' => 'required'
        ]);
        $project_status_arr = $request->except('_token');
        $result = Models\ProjectStatus::create($project_status_arr);
        Session::flash('success_message', 'Project status added successfully!');

        return redirect(url('project-status'));
    }

    public function show($id) {
        // Show a specific post
    }

    public function edit($id) {
        // Show form to edit a post
    }

    public function update(Request $request, $id) {
        // Update a specific post
        return redirect(url('project-status'));
    }

    public function destroy($id) {
        // Delete a specific post
    }
}
