Laravel: Naming Convention & Standards - maple-dev-team/docs GitHub Wiki
Always use single quotes to define strings and use . to concatenate with variables when is possible.
- Exceptions
- When you have single quotes inside the string or using variables inside the string is more readable
Always use const when defining your constants
define() defines constants at run time, while const defines constants at compile time. This gives const a very slight speed edge. define() puts constants in the global scope, although you can include namespaces in your constant name. That means you can’t use define() to define class constants.
Use to start a PHP file
You don't need to close PHP files with: ?>
use Illuminate\Support\Facades\Hash;
$hashedString = Hash::make($plainText);
//or
$hashedString = bcrypt($plainText);
use Illuminate\Support\Facades\Hash;
$result = Hash::check($plainText, $stringHash); // returns true/false
references:
https://laravel.com/docs/8.x/hashing#introduction
https://laravel.com/docs/8.x/helpers#method-bcrypt
https://xqsit.github.io/laravel-coding-guidelines/docs/naming-conventions/
What | How | Good | Bad |
---|---|---|---|
Variable | camelCase | $anyOtherVariable, $somethingMeaningful, $postCount | $any_other_variable, $wx, $count |
Controller | singular | ArticleController | ArticlesController |
Route | snake_case and plural | post_reports/1 | postReport/1 |
Named route | snake_case with dot notation | <syntaxhighlight lang="php">Route::post('name1_name2', 'PostController@example')->name('name1.name2');</syntaxhighlight> | <syntaxhighlight lang="php" style="border: 1px solid red;">Route::post('name1.name2', 'PostController@example')->name('name1-name2');</syntaxhighlight> |
Model | singular | User | Users |
Table | plural | article_comments | article_comment, articleComments |