Convention table names (with underscore)

后端 未结 2 1647
北恋
北恋 2021-02-05 08:53

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

Structure
image_projects (id, project_id, image, ext, size, c

相关标签:
2条回答
  • 2021-02-05 09:27

    Current Laravel version 4.2 table name convention works OK in that way:

    Table name: image_projects

    File name: ImageProject.php

    Class name: ImageProject

    The camel-case class name forced me with an exception to use table name underscores.

    0 讨论(0)
  • 2021-02-05 09:39

    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.

    You can use any of the following options:

    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: If you don't name your class in singular form of what you name your table, you'll have to manually set it in your model:

    class ImageProjects extends Eloquent
    {
        public $table = 'image_projects';
    }
    
    0 讨论(0)
提交回复
热议问题