Hi there, I am following this tutorial on the latest version of Laravel. And when I am trying to dynamically render my shopping cart I get the following error:
Class "App\Product" not found (View: /Users/rosscurrie/mobile-mastery-latest/resources/views/cart/cart.blade.php)
This is my Laravel version: "laravel/framework": "^8.12"
The file directory changes in this version. The product model is now located at: app\Models\Product.php instead of app\Product.php and I think this is the cause of the error.
My CartController.php looks like this:
<?php
namespace App\Http\Controllers;
use App\Models\Product;
use Gloudemans\Shoppingcart\Facades\Cart;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\View\Factory;
use Illuminate\Contracts\View\View;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Routing\Redirector;
class CartController extends Controller
{
/**
* Display a listing of the resource.
*
* @return Application|Factory|View|Response
*/
public function index()
{
return view('cart.cart');
}
/**
* Store a newly created resource in storage.
*
* @param Request $request
* @return Application|RedirectResponse|Redirector
*/
public function store(Request $request)
{
Cart::add($request->id, $request->name, 1, $request->price)
->associate('App\Models\Product'); // this allows us to retrieve our model easier
return redirect()->route('cart.index')->with('success_message', 'Item successfully added to cart!');
}
Hi there, I am following this tutorial on the latest version of Laravel. And when I am trying to dynamically render my shopping cart I get the following error:
This is my Laravel version:
"laravel/framework": "^8.12"
The file directory changes in this version. The product model is now located at:
app\Models\Product.php
instead ofapp\Product.php
and I think this is the cause of the error.My
CartController.php
looks like this:My
cart.blade.php
looks like this:Why am I getting this error? I thought I had fixed it by changing
->associate('App\Product');
to this:->associate('App\Models\Product');