Php 获取拉威尔折扣产品列表
我试图在一个页面中获得所有打折产品,但它不会返回结果 而在主页中返回完全相同的查询结果。Php 获取拉威尔折扣产品列表,php,laravel,Php,Laravel,我试图在一个页面中获得所有打折产品,但它不会返回结果 而在主页中返回完全相同的查询结果。 功能 public function promotions() { $promotions = Discount::with('products')->orderby('id', 'desc')->paginate(12); return view('front.promotions', compact('promotions')); } 路线 Route::get('/p
功能
public function promotions() {
$promotions = Discount::with('products')->orderby('id', 'desc')->paginate(12);
return view('front.promotions', compact('promotions'));
}
路线
Route::get('/promotions', 'frontend\FrontendController@promotions')->name('promotions');
blade
@foreach($promotions as $product)
{{$product->title}} // return nothing!
@endforeach
这是我的$product
dd代码
Discount {#686 ▼
#table: "discounts"
#dates: array:2 [▶]
#fillable: array:4 [▶]
#connection: "mysql"
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#attributes: array:8 [▶]
#original: array:8 [▼
"id" => 4
"value_from" => "2018-02-18"
"value_to" => "2018-02-19"
"amount" => "10000"
"product_id" => 16
"stock" => 25
"created_at" => "2018-02-19 09:05:48"
"updated_at" => "2018-02-19 09:47:10"
]
#changes: []
#casts: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: array:1 [▼
"products" => Product {#697 ▼
#fillable: array:16 [▶]
#connection: "mysql"
#table: null
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#attributes: array:23 [▶]
#original: array:23 [▼
"id" => 16
"title" => "new product"
"slug" => "new-product"
"imageOne" => "productone-1519001703.png"
"imageTwo" => "producttwo-1519001703.jpg"
"short_description" => """
<!DOCTYPE html>\r\n
<html>\r\n
<head>\r\n
</head>\r\n
<body>\r\n
<p>eagtheyh</p>\r\n
</body>\r\n
</html>
"""
"description" => """
<!DOCTYPE html>\r\n
<html>\r\n
<head>\r\n
</head>\r\n
<body>\r\n
<p>shw4 bw 6r uwrurjw ryt jyhkiuggk</p>\r\n
</body>\r\n
</html>
"""
"price" => "100000"
"meta_description" => "gjyrj"
"meta_tags" => "yrujr,ujrtsdjr,jrjurysj,"
"arrivalDays" => "1"
"height" => "546"
"weight" => "56"
"lenght" => "56"
"width" => "56"
"sku" => "47ghg"
"stock" => "24"
"status_id" => 1
"brand_id" => 1
"category_id" => 1
"subcategory_id" => 1
"created_at" => "2018-02-19 07:55:03"
"updated_at" => "2018-02-21 09:58:04"
]
#changes: []
#casts: []
#dates: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: []
#touches: []
+timestamps: true
#hidden: []
#visible: []
#guarded: array:1 [▶]
#slugOptions: null
#configSettings: array:4 [▶]
}
]
#touches: []
+timestamps: true
#hidden: []
#visible: []
#guarded: array:1 [▶]
}
折扣{#686▼
#表:“折扣”
#日期:数组:2[▶]
#可填充:数组:4[▶]
#连接:“mysql”
#主密钥:“id”
#键类型:“int”
+递增:true
#带:[]
#withCount:[]
#每页:15
+存在:正确
+最近被创建:false
#属性:数组:8[▶]
#原件:阵列:8[▼
“id”=>4
“2018-02-18”中的值
“值_至”=>“2018-02-19”
“金额”=>“10000”
“产品标识”=>16
“股票”=>25
“创建于”=>“2018-02-19 09:05:48”
“更新时间:2018-02-19 09:47:10”
]
#更改:[]
#投射:[]
#日期格式:空
#附件:[]
#调度事件:[]
#可观测值:[]
#关系:数组:1[▼
“产品”=>产品{#697▼
#可填充:数组:16[▶]
#连接:“mysql”
#表:空
#主密钥:“id”
#键类型:“int”
+递增:真
#带:[]
#withCount:[]
#每页:15
+存在:正确
+WASSERNTLYCREATED:false
#属性:数组:23[▶]
#原件:阵列:23[▼
“id”=>16
“标题”=>“新产品”
“slug”=>“新产品”
“imageOne”=>“productone-1519001703.png”
“imageTwo”=>“producttwo-1519001703.jpg”
“简短描述”=>“”
\r\n
\r\n
\r\n
\r\n
\r\n
eagtheyh\r\n
\r\n
"""
“说明”=>“”
\r\n
\r\n
\r\n
\r\n
\r\n
shw4 bw 6r UWRJW RYHKIUGGK\r\n
\r\n
"""
“价格”=>“100000”
“元描述”=>“gjyrj”
“meta_标签”=>“yrujr、ujrtsdjr、jrjurysj”
“到达日期”=>“1”
“高度”=>“546”
“重量”=>“56”
“长度”=>“56”
“宽度”=>“56”
“sku”=>“47ghg”
“股票”=>“24”
“状态标识”=>1
“品牌标识”=>1
“类别id”=>1
“子类别_id”=>1
“创建于”=>“2018-02-19 07:55:03”
“更新时间:2018-02-21 09:58:04”
]
#更改:[]
#演员:[]
#日期:[]
#日期格式:空
#附件:[]
#调度事件:[]
#可观测值:[]
#关系:[]
#触摸:[]
+时间戳:真
#隐藏:[]
#可见:[]
#防护:阵列:1[▶]
#slugOptions:null
#配置设置:阵列:4[▶]
}
]
#触摸:[]
+时间戳:真
#隐藏:[]
#可见:[]
#防护:阵列:1[▶]
}
您需要反复查看折扣和产品:
@foreach($promotions as $discount)
{{ $discount->products->title }}
@endforeach
试图在{{$product->title}
@mafortis上获取非对象的属性
,请将{{dd($product)}}
改为此行并显示结果。返回true
仅\@mafortis请显示dd($promotions)的展开结果
在控制器中。@mafortis看起来折扣只有一种产品。我已经更新了代码。