我試圖通過價格訂購我的產品,一旦客戶點擊產品頁面內的訂單。我不斷收到下一個錯誤:Undefined index:title(View:C:\ xampp \ htdocs \ eshop \ resources \ views \ content \ item.blade.php)。 我的'item.blade.php'是顯示單獨頁面中產品的較大尺寸的頁面。我認爲這個問題是我的控制器項目函數內部或IM我的模型的getItem功能,我可能是錯的...將不勝感激,如果你能幫助我.ThanksLaravel訂單發行
我的路線:
Route::get('shop/{category_url}/sorting-{sort?}', '[email protected]');
我的看法在content.products:
@if($products)
<br><br>
<a href=" {{ url('shop/'.$category['url'].'/sorting-asc')}}" style="color:black"> High to low</a> |
<a href=" {{ url('shop/'.$category['url'].'/sorting-desc')}}" style="color:black">Low to high</a>
我item.blade.php:
@extends ('master')
@section('content')
<div class="row">
<div class="col-md-12 text-center">
@if('item')
<h1>{{ $item['title']}}</h1>
<p><img width="500" src="{{ asset ('images/' . $item['image'])}}" </p>
<p>{!! $item['article'] !!}</p>
<p><b>Price on site:</b>{{ $item['price']}}$</p>
<p>
@if(Cart::get($item['id']))
<input disabled="disabled" type="button" value="In Cart!" class="btn btn-success">
@else
<input data-id="{{ $item['id']}}" type="button" value="+ Add to cart" class="btn btn-success add-to-cart">
@endif
<a href="{{ url('shop/checkout') }}" class="btn btn-primary">Checkout</a>
</p>
@else
<p class="text-center" style="font-size: 18px">No product details ...</p>
@endif
</p>
@endsection
我的控制器:
public function products(Request $request, $category_url, $sort= 'ASC'){
Product::getProducts($category_url, self:: $data);
$catsort = Categorie::where('url', '=', $category_url)->first();
$products = Product::where('categorie_id', $catsort->id)->orderBy('price', $sort)->get();
return view('content.products', self::$data ,['products' => $products, 'sort' => $sort]);
}
public function item($category_url, $product_url){
Product::getItem($product_url, self::$data);
return view('content.item', self::$data);
}
我的模型:
static public function getProducts($category_url, &$data){
$data['products']=$data['category']=[];
if ($category=Categorie::where('url','=', $category_url)->first()){
$category= $category->toArray();
$data['category']=$category;
$data['title']=$data['title']. ' | ' . $category['title'];
if ($products=Categorie::find($category['id'])->products){
$data['products']= $products->toArray();
}
}
}
static public function getItem($product_url, &$data) {
$data['item'] = [];
if ($product = Product::where('url', '=', $product_url)->first()) {
$product = $product->toArray();
$data['item'] = $product;
$data['title'] .= '|' . $product['title'];
}
}
**註釋不適用於擴展討論或調試會話**;這個對話已經[轉移到聊天](http://chat.stackoverflow.com/rooms/152083/discussion-on-question-by-pioneer2017-issue-with-laravel-orderby)。如果您在評論中要求您提供澄清或代碼,您需要將其編輯到您的問題中。 –