Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5 Naming Conventions

Tags:

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

like image 367
Yohan Hirimuthugoda Avatar asked Jan 14 '17 22:01

Yohan Hirimuthugoda


People also ask

What is naming convention in laravel?

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.

What are the naming conventions in PHP?

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 @ .

What is the meaning of naming convention?

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.


1 Answers

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.

like image 197
Alexey Mezenin Avatar answered Oct 10 '22 14:10

Alexey Mezenin