0

1 year agoby Sunil

Class 'APP\Model\Review' not found

when I write same code you have mention on video of rest api.

return ReviewResource::collection($product->reviews);

its giving me error as Class 'APP\Model\Review' not found

/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasRelationships.php670

ReviewController.php as below 


<?php

namespace App\Http\Controllers;
use App\Http\Resources\Productreview\ReviewResource;

use App\Model\Product;
use App\Model\Review;


use Illuminate\Http\Request;

class ReviewController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Product $product)
    {
       
       //return $product;
        return ReviewResource::collection($product->reviews);
    }

    /**
     * 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)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  \App\Model\Review  $review
     * @return \Illuminate\Http\Response
     */
    public function show(Review $review)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  \App\Model\Review  $review
     * @return \Illuminate\Http\Response
     */
    public function edit(Review $review)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\Model\Review  $review
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, Review $review)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  \App\Model\Review  $review
     * @return \Illuminate\Http\Response
     */
    public function destroy(Review $review)
    {
        //
    }
}

Can you have a look.

5

Ajinkya shivaji pawar replied 1 year ago

1

first check you create the model or not other wise fire the php artisan make:model review for the same and create the model then use the use App\review in the controller

5

Ajinkya shivaji pawar replied 1 year ago

0

dear App\review model use in top then your problem get resolve

89

Sarthak Shrivastava replied 1 year ago

1

Hey, it looks like you have problem on your Product model relationship.

Please check Product model and change APP\Model\Review to App\Model\Review.

Hope this will work.

Ask Question
Most Visited
Categories