【发布时间】:2020-01-16 13:20:04
【问题描述】:
我是 laravel 框架的新手。我无法通过控制器中的价格获得工作药物。
我的模型;
use Illuminate\Database\Eloquent\Model;
class Medicine extends Model
{
protected $table = 'medicine';
protected $fillable = [];
protected $guarded = [];
public function withPrice()
{
return $this->hasMany('App\Models\MedicinePrice', 'medicine_id', 'id');
}
}
在我的应用服务中;
public function getRecentEntries()
{
$medicines = Medicine::orderBy('id','DESC')->take(10)->get()->toArray();
dd($medicines);
return $this->formatMedicine($medicines);
}
药表:https://take.ms/EHrwd 药品价格表:https://take.ms/BMTJW
有什么帮助吗?非常感谢。
【问题讨论】:
标签: laravel eloquent belongs-to