laravel - Laravel 命名约定,相同的实体还是单独的实体?
问题描述
所以我正在研究一个房地产系统,我们有属性,然后我们有属性类型(可以是房屋、餐厅、土地等)。所以难题是:我们是将属性类型视为属性的一部分,还是将它们视为单独的实体?
控制器:
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');
}
推荐阅读
- python - 在具有一个离散变量和一个连续变量的函数空间上进行优化
- javascript - React and Ably,在投票教程中获得 404 cannot GET /publish and /subscribe 错误
- python-3.x - 使用 var 的值动态构建类名
- python - 改进此嵌套循环的执行时间
- deepar - 如何使用 Glunts DeepAR 预测未知的未来目标值?
- spring-boot - 如何通过@Import 在 SpringBoot 中导入内部类?
- bash - ZSH 脚本中的递增数
- android - 检查用户是否已授予访问附近设备的权限
- c++ - 请求从 `const char[]` 转换为非标量类型
- html - 更漂亮 - 禁用 html 标签的自动关闭