What is the correctly table name of this table in Laravel 3/4?

Structure
image_projects (id, project_id, image, ext, size, created_at, updated_at, active)

image_projects
imageprojects
imageProjects

还有,我如何创建模型?

app/models/image_projects.php
app/models/imageprojects.php
app/models/imageProjects.php
app/models/image/projects.php
app/models/projects/image.php

推荐答案

It makes no difference what you name your table, as long as you then name the file & class in singular form, with the class name starting with an uppercase letter.

您可以使用以下任一选项:

Table name: image_projects

File name: ImageProject.php

Class name: ImageProject


Table name: imageprojects

File name: Imageproject.php

Class name: Imageproject


Table name: imageProjects

File name: ImageProject.php

Class name: ImageProject

In this case you'll have to set the $table property yourself.


Remember:如果你没有以单数形式命名你的类,你必须在你的模型中手动设置它:

class ImageProjects extends Eloquent
{
    public $table = 'image_projects';
}

Laravel相关问答推荐

如何在自定义表单请求中获取错误验证数据

Laravel Livewire 组件属性在 div 类中为空

使用 laravel 根据当月显示注册用户列表

使用 Amazon S3 的 Storage::get() 返回 false

使用 Eloquent 的 Laravel 块方法

Laravel 5.1 如何在Blade 文件上使用 {{ old('') }} 助手进行无线电输入

从 laravel/blade 中的数组创建逗号分隔列表?

转储或 dd laravel 在结果前添加字符时出错

如何使用 Eloquent Laravel 更新集合

Twilio 查找 API 不起作用?

在 Laravel 中下载后如何重定向?

laravel 4 - 如何限制(采取和跳过)Eloquent的 ORM?

如何在 Laravel Eloquent 中 Select 某些字段?

将图标添加到 Laravelcollective 提交按钮

PHP Laravel:如何获取客户端浏览器/设备?

约定表名(带下划线)

无法打开流:没有这样的文件或目录(Laravel)

如何在 Laravel 测试中禁用选定的中间件

复合唯一密钥验证 - laravel

Laravel 数据迁移