An error occurred while loading the file. Please try again.
-
Nitipat authored496d8679
<?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)
{
//
}