I am bit confused with Laravel conventions as I am new to this framework. I am following Jeffrey Way Laracasts videos he uses Plural for Controller names.
E.g.: PagesController, Cards Controller, PostsController
But if I refer official documentations of Laravel > Controllers and Laravel > Tutorials > Quick Start > Intermediate Task List it uses Singular names.
E.g.: PhotoController, TaskController
Can anybody please list down the official coding conventions for following entities?
Tables: posts, comments, post_comments or Post, Comment, PostComment
Columns: id, post_id, comment_id or id, postId, commentId
Controllers: PagesController, Cards Controller, PostsController or PhotoController, TaskController
Models: Pages, Cards, Posts or Page, Card, Post
Naming Models in LaravelA model should be in singular, no spacing between words, and capitalised. For example: `User` (`\App\User` or `\App\Models\User`, etc), `ForumThread`, `Comment`. Bad examples: Users , ForumPosts , blogpost , blog_post , Blog_posts . But of course you can just set $this->table in your model.
Variable naming rules PHP First, every variable must start with the special character $ . Variables can then start with an underscore ( _ ) or any letter, but not with a number or a special character. The names of your variables cannot contain special characters such as & , % , # , or @ .
A naming convention is a convention (generally agreed scheme) for naming things. Conventions differ in their intents, which may include to: Allow useful information to be deduced from the names based on regularities.
Tables: posts, comments, comment_post
Columns: id, post_id, comment_id
Controllers: PhotoController, TaskController
Models: Page, Card, Post
For more details check out my Laravel naming conventions table.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With