• Nitipat's avatar
    ok · 496d8679
    Nitipat authored
    496d8679
CommentController.php 1.85 KiB
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Post;
use App\Comment;
use Auth;
use App\Http\Requests\StoreCommentRequest;
class CommentController extends Controller
    /**
     * Display a listing of the resource.
     * @return \Illuminate\Http\Response
    public function index()
    /**
     * Show the form for creating a new resource.
     * @return \Illuminate\Http\Response
    public function create()
    /**
     * Store a newly created resource in storage.
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
    public function store(StoreCommentRequest $request, $post)
        $postModel = Post::find($post);
        $input = array_merge(['user_id' => Auth::user()->id], $request->all());
        $comment_id = $postModel->comments()->create($input)->id;
        $comment = Comment::find($comment_id);
        return response()->json($comment, 201);
    /**
     * Display the specified resource.
     * @param  int  $id
     * @return \Illuminate\Http\Response
    public function show($id)
    /**
     * Show the form for editing the specified resource.
     * @param  int  $id
     * @return \Illuminate\Http\Response
    public function edit($id)