我在想拉拉维尔的事。我有一个型号的‘电话’和一个方法计数产品()。每个型号的“手机”都有很多“产品”。
我用countproducts()来计算手机拥有的产品。
$phones=Phone::where(function($query){
if(isset($min_weight) && isset($max_weight)){
$query-> where('weight','>=',$min_weight);
$query-> where('weight','<=',$max_weight);
}我现在就是这样查询电话的。
是否可以只查询和显示手机,比如50多个产品??
提前感谢
编辑: Phone.php
<?php namespace App;
use Illuminate\Database\Eloquent\Model;
class Phone extends Model {
public function productnum()
{
return $this->hasMany('App\Product');
}
public function productStore()
{
return $this->hasOne('App\Store');
}
public function category(){
return $this->belongsTo('App\Category');
}
public function minprice(){
return $this->productnum->min('newprice');
}
public function maxprice(){
return $this->productnum->max('newprice');
}
}Product.php
<?php namespace App;
use Illuminate\Database\Eloquent\Model;
class Product extends Model {
public function manufacturer(){
return $this->hasOne('manufacturer');
}
public function phone(){
return $this->belongsto('App\Phone');
}
public function category(){
return $this->belongsto('App\Category');
}
public function store(){
return $this->belongsto('App\Store');
}发布于 2015-04-04 11:15:54
https://stackoverflow.com/questions/29445568
复制相似问题