在此圖中,其余表鏈接到 datainfo 表。我需要從 datainfo 表中檢索整個表資料。 在這張照片中,我展示了表格本身
uj5u.com熱心網友回復:
您可以為每個表創建 Eloquent 模型并定義它們之間的關系。這是正確的 Laravel 方式。
假設您的datainfo表代表您的 Datainfo 模型,您的cars表代表汽車模型。與washtypes和相同boxes。
然后根據您的關系型別在 Datainfo 模型中定義關系。
class Datainfo extends Model
{
public function cars()
{
return $this->hasMany(Car::class);
}
}
您也可以使用hasOne代替hasMany一對一的關系
類似地,創建關系定義函式為washtypes()和boxes()。
然后使用諸如在控制器中思考之類的方法獲取包含所有相關資料的 Datainfo
return Datainfo::with('cars','washtypes','boxes')->get();
或者,您可以獲取計數
return Datainfo::with('cars','washtypes','boxes')->count();
計算日期
return Datainfo::with('cars','washtypes','boxes')->where('created_at',$date_var)->count();
如果您只想要與汽車、洗滌型別或盒子相關的資料資訊:
return Datainfo::has('cars','washtypes','boxes')->where('created_at',$date_var)->count();
uj5u.com熱心網友回復:
使用laravel eloquent join子句,https: //laravel.com/docs/8.x/queries#joins 當天的總金額可以使用eloquent sum和group by方法基于日期
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/393638.html
