| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- <?php
- namespace App\Http\Controllers;
- use App\Models\Comment;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\DB;
- class CommentController extends Controller
- {
- /**
- * Display a listing of the resource.
- *
- * @return \Illuminate\Http\Response
- */
- public function index()
- {
- //
- }
- public function index_count()
- {
- return Comment::select('blogId', DB::raw('count(*) as total'))->groupBy('blogId')->reorder('total', 'desc')->get();
- }
- public function index_by_blog(Request $request)
- {
- return Comment::where('blogId', '=', $request->blogId)->get();
- }
- /**
- * 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(Request $request)
- {
- Comment::insert([
- 'authorId' => $request->user()->id,
- 'comment' => $request->comment,
- 'blogId' => $request->blogId,
- 'created_at' => now(),
- 'updated_at' => now(),
- ]);
- }
- /**
- * Display the specified resource.
- *
- * @param \App\Models\Comment $comment
- * @return \Illuminate\Http\Response
- */
- public function show(Request $request)
- {
- return Comment::where('id', '=', $request->commentId)->first();
- }
- /**
- * Show the form for editing the specified resource.
- *
- * @param \App\Models\Comment $comment
- * @return \Illuminate\Http\Response
- */
- public function edit(Comment $comment)
- {
- //
- }
- /**
- * Update the specified resource in storage.
- *
- * @param \Illuminate\Http\Request $request
- * @param \App\Models\Comment $comment
- * @return \Illuminate\Http\Response
- */
- public function update(Request $request, Comment $comment)
- {
- //
- }
- /**
- * Remove the specified resource from storage.
- *
- * @param \App\Models\Comment $comment
- * @return \Illuminate\Http\Response
- */
- public function destroy(Request $request)
- {
- Comment::where('id', '=', $request->commentId)->delete();
- }
- }
|