Im getting this error:
"Undefined variable: books (View: C:\xampp\htdocs\Shop\resources\views\welcome.blade.php)"
This is my Model
namespace App;
use Illuminate\Database\Eloquent\Model;
class Product extends Model
{
protected $fillable=
['name','description','condition','category_id','image'];
public function category()
{
$this->belongsTo(Category::class);
}
}
This is my ProductsController
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Category;
use App\Product;
class ProductsController extends Controller
{
public function index()
{
$products=Product::all();
return view('admin.product.index',compact('products'));
}
public function create()
{
$categories = Category::pluck('name','id');
return view ('admin.product.create', compact('categories'));
}
public function store(Request $request)
{
$product=$request->except('image');
//validation
$this->validate($request,[
'name' => 'required',
'condition' => 'required',
'image' => 'image|mimes:png,jpg,jpeg|max:10000'
]);
//image upload
$image=$request->image;
if($image){
$imageName=$image->getClientOriginalName();
$image->move('images',$imageName);
$product['image']=$imageName;
}
Product::create($product);
return redirect()->route('admin.index');
}
This is my Welcome.blade.php
<div class="row">
@forelse( $books as $book)
<div class="column-prod">
<a href="">
<div class="card-prod">
<center><img src="/css/aa.jpg" style="width: 300px; height: 300px;"></center> </a>
<div class="container-prod">
<h2></h2>
<p class="title"></p>
<p class="price">Php 450.00</p>
<p><button class="button"><i class="fas fa-cart-arrow-down"></i>Add to Cart</button></p>
<p><button class="button"><i class="fas fa-heart"></i> Add to Wishlist</button></p>
</div>
</div>
</div>
@empty
<h3> No Books </h3>
@endforelse
</div> <!--Div all end-->
@endsection
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire