mardi 14 avril 2020

Undefined variable: products (View: /projects/ProjectWebsite/resources/views/shop/index.blade.php)

please can someone help, This is my model that i have created

namespace App;

use Illuminate\Database\Eloquent\Model;

class Product extends Model
{
    protected $fillable = ['imagePath', 'title', 'description', 'price'];
}

this is the blade file

@extends('layouts.master')

@section('title')

Checkouts Page

@endsection

@section('content')

@foreach($products->chunk(3) as $productChunk)

<div class="row">

@foreach($productChunk as $product)

<div class="col-sm-6 col-md-4">
<div class="thumbnail">
<img src="" height="200" width="300"> 
<div class="caption">
<h3></h3>
<p class="description"> </p>

 <div class="clearfix">
 <div class="pull-left price"></div>
 <a href="#" class="btn btn-success pull-right" role="button">Add to Basket</a>
 </div>
 </div>
 </div>
 </div>


@endforeach
</div>

@endforeach

@endsection

this is the error i have got : Undefined variable: products (View: /projects/ProjectWebsite/resources/views/shop/index.blade.php)

this is the controller (edit) forgot to add first time i posted

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Product;

class ProductController extends Controller

{
      public function getIndex()
    {


         $products = Product::all();        
         return view('shop.index', ['products' => $products]);

    }

 }

this is the route i have set up Route::get('/', 'ProductController@getIndex');



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire