Laravel 命名约定,相同的实体还是不同的实体?
Laravel naming convention, same entity or separate entities?
所以我正在研究房地产系统,我们有属性,然后我们有 属性 类型(可以是房屋、餐厅、土地等)。所以难题是:我们是将 属性 类型视为属性的一部分,还是将它们视为单独的实体?
控制器:
PropertiesController
PropertyTypesController
或
PropertiesController
TypesController
型号:
Property
PropertyType
或
Property
Type
查看:
views/properties/index.blade.php
views/properties/show.blade.php
views/properties/edit.blade.php
views/properties/types/index.blade.php
views/properties/types/show.blade.php
views/properties/types/edit.blade.php
views/properties/types/create.blade.php
或
views/properties/index.blade.php
views/properties/show.blade.php
views/properties/edit.blade.php
views/properties/create.blade.php
views/property_types/index.blade.php
views/property_types/show.blade.php
views/property_types/edit.blade.php
views/property_types/create.blade.php
我认为这里最重要的问题是这个。
目前或将来是否有可能存在另一种模型/类型概念?例如 PaymentTypes 或 UserTypes 等等。
如果您已经看到发生这种情况的可能性很小,我肯定会选择更详细的 PropertyTypes 选项。还要记住,当涉及到关系时,您仍然可以让它们不那么冗长,以保持您的代码简单,例如这样。
public function types() {
return $this->belongsToMany('App\PropertyType');
}
简答:PropertyType 优于 Type
您应该尽量使您的变量(或 Class 名称)具有描述性(保持简短)。
而不是 $order->status
和 $type
最好使用类似的东西:
$order->deliveryStatus
和 $itemType
因为您永远不知道什么时候需要添加不同类型的 'status' 或 'type'。因此你应该使用更具描述性的命名
所以我正在研究房地产系统,我们有属性,然后我们有 属性 类型(可以是房屋、餐厅、土地等)。所以难题是:我们是将 属性 类型视为属性的一部分,还是将它们视为单独的实体?
控制器:
PropertiesController
PropertyTypesController
或
PropertiesController
TypesController
型号:
Property
PropertyType
或
Property
Type
查看:
views/properties/index.blade.php
views/properties/show.blade.php
views/properties/edit.blade.php
views/properties/types/index.blade.php
views/properties/types/show.blade.php
views/properties/types/edit.blade.php
views/properties/types/create.blade.php
或
views/properties/index.blade.php
views/properties/show.blade.php
views/properties/edit.blade.php
views/properties/create.blade.php
views/property_types/index.blade.php
views/property_types/show.blade.php
views/property_types/edit.blade.php
views/property_types/create.blade.php
我认为这里最重要的问题是这个。
目前或将来是否有可能存在另一种模型/类型概念?例如 PaymentTypes 或 UserTypes 等等。
如果您已经看到发生这种情况的可能性很小,我肯定会选择更详细的 PropertyTypes 选项。还要记住,当涉及到关系时,您仍然可以让它们不那么冗长,以保持您的代码简单,例如这样。
public function types() {
return $this->belongsToMany('App\PropertyType');
}
简答:PropertyType 优于 Type
您应该尽量使您的变量(或 Class 名称)具有描述性(保持简短)。
而不是 $order->status
和 $type
最好使用类似的东西:
$order->deliveryStatus
和 $itemType
因为您永远不知道什么时候需要添加不同类型的 'status' 或 'type'。因此你应该使用更具描述性的命名