lundi 30 juillet 2018

htmlspecialchars() expects parameter 1 to be string, object given

This is Controller. I named it CartController

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Gloudemans\Shoppingcart\Facades\Cart;
use App\Product;

class CartController extends Controller
{

public function index()
{
    $cartItems=Cart::content();
    return view('cart.index', compact('cartItems'));
}

public function edit($id)
{
    $product=Product::find($id);

    Cart::add($id,$product->name,'1',$product->price);
}

This is my welcome.blade.php. This is the page where I display all my Items.

<div class="row">
@forelse($books->chunk(4) as $chunk)
  @foreach($chunk as $book)
    <div class="column-prod">
<a href="">
<div class="card-prod">
<center><img src=""  style="width: 300px; height: 300px;"></center> </a>
  <div class="container-prod">
    <h2></h2>
    <p class="title"></p>
    <p class="price">₱ </p>

    <p><a href="" class="button"><i class="fas fa-cart-arrow-down"></i>Add to Cart</button></a></p>
    <p><button class="button"><i class="fas fa-heart"></i>  Add to Wishlist</button></p>
  </div>
  </div>
</div>

@endforeach 
@empty
<h3> No Books </h3>
@endforelse 


 </div> <!--Div all end-->

This is the codes of my Cart Page. When the user click add to cart in the welcome page, his/her chosen items will be place in this page.

  <h3> Cart Items </h3>

  <!--TABLE NAMESSS-->
                    <table class="table table-hover">
                        <thead>
                            <tr>
                               <th scope="col">Image</th>
                               <th scope="col">Name</th>
                               <th scope="col">Price</th>
                               <th scope="col">Quantity</th>

                            </tr>
                        </thead>


            <tbody> 
                @foreach($cartItems as $cartItem)
                <li></li>
                    <tr>

                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>

                    </tr>
                @endforeach
            </tbody>
        </table>

This is my route.

Route::get('/', function () {
return view('welcome')->with(['books' => \App\Product::all()]);
});

Route::get('/cart','ShopController@cart');

Route::get('/signin','ShopController@signin');



Route::resource('/cart','CartController');

Route::get('/wishlist','ShopController@wish');



Auth::routes();

Route::get('/logout', 'Auth\LoginController@logout');

Route::get('/home', 'HomeController@index');

Route::group(['prefix' => 'admin', 'middleware' => 'auth'], function(){
        Route::get('/',function(){
            return view('admin.index');
        })->name('admin.index');


        Route::resource('product','ProductsController');
        Route::resource('category','CategoriesController');
});

Route::get('/categ', function(){
return view ('admin.category.categ_index');

});

I'm confused I don't know how to fix my error. This is the complete error that the system return.

"htmlspecialchars() expects parameter 1 to be string, object given (View: C:\xampp\htdocs\Shop\resources\views\welcome.blade.php)"

I hope you can help me in solving this. Your answers are very much appreciated.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2AmTTS0
via IFTTT

Aucun commentaire:

Enregistrer un commentaire