Laravel Naming conventions

WhatHowShould FollowNot to Use
ControllersingularPostControllerPostsController
Routepluralposts/1post/1
Named routesnake_case with dot notationusers.show_activeusers.show-active, show-active-users
ModelsingularUserUsers
hasOne or belongsTo relationshipsingularpostCommentpostComments, post_comment
All other relationshipspluralpostCommentspostComment, post_comments
Tablepluralpost_commentspost_comment, postComments
Pivot tablesingular model names in alphabetical orderpost_useruser_post, posts_users
Model propertysnake_case$model->created_at$model->createdAt
Foreign keysingular model name with _id suffixpost_idPostId, id_post, posts_id
Primary keyidcustom_id
Migrationdate_create_posts_table2019_05_08_posts
MethodcamelCasegetAllget_all
Method in resource controllertablestoresavePost
VariablecamelCase$postsWithAuthor$posts_with_creator

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s