gpt4 book ai didi

laravel - Laravel上的Facade\Ignition\Exceptions\ViewException错误?

转载 作者:行者123 更新时间:2023-12-03 08:39:57 24 4
gpt4 key购买 nike

0
我到达了我无法确定的部分。尝试在主页上显示产品时,出现以下错误:Undefined variable: products (View: /home/acer/test/project_basket/basket/resources/views/home.blade.php)对我来说,这是php中的第一个项目,我不太会用这种语言进行练习。
home.blade.php:

@section('content')
<div class="card-deck">


/*Problem Here */
@foreach ($products as $product)
<div class="card">
<img src="{{ $product->imagePath }}" class="card-img-top" alt="...">
<div class="card-body">
<h5 class="card-title">{{ $product->title }}</h5>
<p class="color">{{ $product->color }}</p>
<a href="#" class="btn btn-danger">Buy Now</a>
<button type="button" class="btn btn-primary float-right">Add to Cart</button>
<div class="price">${{ $product->price }}/div>
</div>
</div>
@endsection
Product.php
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Product extends Model
{
protected $fillable = ['imagePath', 'title', 'price', 'color'];
}
ProductController.php:
<?php

namespace App\Http\Controllers;

use App\Product;
use Illuminate\Http\Request;
//use Illuminate\Http\Request;

class ProductController extends Controller

{
/**
*@return \Illuminate\Http\Response
*/
public function index()
{
$products = Product::inRandomorder()->take(6)->get();
return view('home')->with('products', $products);
}
}
路线:
//Route::view('/`home`', 'home');


Route::get('/', 'ProductController@index')->name('home');

Auth::routes();

Route::get('/home', 'ProfilesController@index')->name('home');
Route::get('/', 'ProfilesController@index')->name('welcome');

//Route::get('/home', 'DasboardController@index')->name('dashboard');

最佳答案

您在“命中” /home端点,该端点查看您的路线指向ProfilesController,但是您正在使用ProductController,因此在web.php中编写了错误的Controller

关于laravel - Laravel上的Facade\Ignition\Exceptions\ViewException错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62603391/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com