app/Http/Controllers/ProductReviewsController.php
/**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
Store a newly created resource in storage.
Store a newly created resource in storage .
public function store(Request $request, $id)
    {
        $this->validate($request, [
            "comment" => 'required'
        ]);
        $product = products::find($id);
        $review = new product_reviews;
        $review->user_id = auth::user()->id;
        $review->comment= $request['comment'];
        if($product != null)
        {
            $review->product_id = $product->id;
            $review->save();
            $response = [
                "status" => "success",
                "message" => "Review successfully added",
                "data" => $review
            ];
            return response()->json($response, 201);
        }
        else
        {
            $response = [
                "status" => "error",
                "message" => "The product you are trying to add a review for is not available",
                "data" => null
            ];
            return response()->json($response, 404);
        }
    }
public function store ( Request $ request , $ id ) { $ this -> validate ( $ request , [ " comment " => 'required' ] ) ; $ product = products :: find ( $ id ) ; $ review = new product_reviews ; $ review -> user_id = auth :: user ( ) -> id ; $ review -> comment = $ request [ 'comment' ] ; if ( $ product != null ) { $ review -> product_id = $ product -> id ; $ review -> save ( ) ; $ response = [ " status " => " success " , " message " => " Review successfully added " , " data " => $ review ] ; return response ( ) -> json ( $ response , 201 ) ; } else { $ response = [ " status " => " error " , " message " => " The product you are trying to add a review for is not available " , " data " => null ] ; return response ( ) -> json ( $ response , 404 ) ; } }
Store a newly created resource in storage.
Store a newly created resource in storage .
//