<reponame>segunemma2003/akawo<?php

namespace App\Http\Controllers;

use App\Http\Requests\ReviewsRequest;
use App\Models\Reviews;

class ReviewsController extends Controller
{
    public function index()
    {
        $reviews = Reviews::where('user_id', auth()->user()->id)->latest()->get();

        return response(['data' => $reviews ], 200);
    }

    public function store(ReviewsRequest $request)
    {
        $reviews = Reviews::create($request->all());

        return response(['data' => $reviews ], 201);

    }

    public function show($id)
    {
        $reviews = Reviews::findOrFail($id);

        return response(['data', $reviews ], 200);
    }

    public function update(ReviewsRequest $request, $id)
    {
        $reviews = Reviews::findOrFail($id);
        $reviews->update($request->all());

        return response(['data' => $reviews ], 200);
    }

    public function destroy($id)
    {
        Reviews::destroy($id);

        return response(['data' => null ], 204);
    }
}
