簡體   English   中英

在具有兩個不同模型但名稱相同的公共功能時,是否有任何問題?

[英]Any issue with having two public functions, in different models, but with the same name?

我正在使用Laravel框架編寫Web應用程序。 我有兩個模型,其中我使用相同的名稱創建了一個公共函數,以形成一個口才關系。 我想知道這是不好的做法,還是會給我帶來任何問題。

這是我的WorkOrder模型的代碼:

/**
 * Get the aircraft that owns the work order.
 */
public function aircraft()
{
    return $this->belongsTo(Aircraft::class);
}

這是我的客戶模型代碼:

/**
 * Get all of the aircraft for the customer.
 */
public function aircraft()
{
    return $this->hasMany(Aircraft::class);
}

一切都很好,並且不會有任何問題,因為@Ohgodwhy指出您想對hasManybelongsToMany關系的函數名進行復數。 在這種情況下,這是有爭議的,因為飛機是飛機的復數。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM