0

i'm just thinking here, i had multiple tables related to the student, things like: history, bulletin, parents, course, and a lot more... when i need create a new student, all this tables need to be filled. i'm using Laravel and the recomended is create a model to each table, my problem is now, naming the model name, what's the best aproach? model with table name or a name related to what the model is?

There are only two hard things in Computer Science: cache invalidation and naming things.

-- Phil Karlton

2
  • Well you can name it anything you want as long as the model name is clear on what it should store. Commented Nov 14, 2017 at 14:36
  • 1
    As I know a good practice is to name the model at singular while the table plural. Eg. model: Bulletin, table: bulettins, model: Parent, table: parents. I guess the logic is that the Model should be singular because it represents a single db row/entry. But sure you can name them as per your needs. Commented Nov 14, 2017 at 14:37

1 Answer 1

1

There are many conventions for "Models" - Laravel just doesn't bottleneck you or your project into using any one method as long as the model name is clear and has its own table you are following best practices.

for organizational purposes you can add all the related models under the same folder,this is something for you (and your development team, if you're a part of one) to decide on.

   ├── app
   │   ├── Models <---- folder
   │   │   ├── Students <---- folder
   │   │   │   ├── Student.php    \
   │   │   │   ├── History.php     \ ____ Models
   │   │   │   ├── Bulletin.php    /
   │   │   │   ├── Course.php     /
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.