Загрузка...

Laravel Naming Conventions | Naming Conventions for Laravel Controllers, Models, Methods, Variables

Laravel Naming Conventions is a set of rules that we require to apply while choosing the names for variables, functions, models, controllers, relationships in Laravel projects. Every Laravel Developer must follow Laravel Naming Conventions in their Laravel Projects. Laravel Naming Conventions for Routes :- Suppose we want to manage CRUD (create, read, update and delete) for Users then below Laravel naming conventions we must follow :- //Listing Route::get('/users', 'UserController@index'); //Create Route::get('/users/create', 'UserController@create'); //Show Route::get('/users/{id}', 'UserController@show'); //Edit Route::get('/users/{id}/edit', 'UserController@edit'); //Delete Route::delete('/users/{id}/delete', 'UserController@delete'); Laravel Naming Conventions for Controllers :- Controllers names should be in singular case, no spacing between words and end with "Controller". Also, each word should be capitalised (i.e. UserController, ProductController). Laravel Naming Conventions for Methods :- Methods or Functions should be in camelCase in which first character must always be in lower case like getUsers or getProducts Also, Methods can be in singular or plural case. user, product, getUser or getProduct in case of fetching single user or product users, products, getUsers or getProducts in case of fetching multiple users or products Laravel Naming Conventions for Variables :- Variables should be in camelCase, with the first character in lower case and no spacing between words.  Variables with single word must be like $user, $product, $getUser, $getProduct  Variables with multiple words must be like $users, $products, $getUsers, $getProducts Laravel Naming Conventions for Models :- A model name should be in singular, no spacing between words, and capitalised. Like: User, Product model Laravel Naming Conventions for Relationships :- Relationships methods should be camelCase with the first character in lower case. Like: category, section, productFilters Laravel Naming Conventions for Blade files :- Blade file names should be in snake_case with all characters in lower case and underscore between words. Like: login_register.blade.php, products.blade.php Laravel Naming Conventions for Database Tables :- Database table names should be in snake_case with all lower case and use underscores to separate words and should be in plural form. Like: users, products, delivery_addresses Laravel Naming Conventions for Database Table Column Names :- Table column names should be in snake_case with all lower case and use underscores to separate words. Like: id, user_id, created_at We have followed 80% of Laravel Naming Conventions in our Laravel E-commerce Series so please follow and check. In Upcoming Laravel 9 Multi-Vendor E-commerce Series, we try to follow 100% of Laravel Naming Conventions. Follow below playlist to make Laravel E-commerce Website :- https://www.youtube.com/playlist?list=PLLUtELdNs2ZaHaFmydqjcQ-YyeQ19Cd6u Join this channel to get Laravel projects with complete code/support: https://www.youtube.com/channel/UCExO2i-tLU1NyVZD6zOJQlw/join #laraveltutorial #laravelecommerce #laravelfeatures #laraveldevelopment

Видео Laravel Naming Conventions | Naming Conventions for Laravel Controllers, Models, Methods, Variables автора PHP для новичков
Страницу в закладки Мои закладки
Все заметки Новая заметка Страницу в заметки