Laravel Standard
Laravel Standard
ENV file.
- The .env.example is the environment of our
project. All the configurations are here
especially the database of the project. By
removing the .example will activate the env
file or simply ask for your co-developers for
the existing env file.
Gitignore file.
- Here are lists of files, directory that we don’t
want to push on remote repo. .env,
storage/*.key, public/storage are some files
that must there.
Public Folder
- All files under the public folder are the files that are
publicly viewed on a browser.
CSS – the location of CSS libraries (ex. bootstrap), custom
CSS and CSS plugins.
Images – all the images, logos that was used on the web
app.
JS – All custom JavaScript code is placed here.
Plugin - the location where you find libraries, and plugins.
Storage – Here are the files/images that was uploaded
from web app. It uses php artisan storage:link to symlink
the storage folder into public
Note: Some folders are not specified since there are different features per project, so the
folder structure is dependent on the project, but the items mentioned before are the
common folder structure.
MVC Model
- Should be singular case, no spacing between words, and use PascalCase format
- E.g. MobileUser, BusinessInfo, TransactionDetail
- ORMs
If using “belongsTo” or “hasOne” relationship, make the function name be singular, and if
all other relationships use plural.
Do’s Don’ts
- Migration
a. Database Tables – should be in lower case, snake_case and should be in plural form.
(e.g. user_accounts, business_infos)
b. Column names – should be in lower case, and snake_case and shouldn’t reference
the table name. (e.g. id, application_type, status, mode_of_payment)
c. Foreign keys – should be the model name (singular) , with ‘_id’ appended to it
(assuming the PK in the other table is ‘id) (e.g. user_id, post_id, business_info_id)
d. Primary keys – should be id
1. Structures
Folderize all the blade file depends on their category
(E.g. layout/master.blade.php, layout/sidebar.blade.php, layout/navbar.blade.php)
2. Blade files
a. File name – snake_case (E.g. application_details.blade.php)
b. CSS ID – snake_case (E.g. btn_save, btn_delete)
c. CSS class – hypen-separated words (E.g. col-12, lists-groups)
3. The master.blade.php
All the CSS plugins and JS plugins are located on here. It also has the nexlibrary.js (A
custom JS library of the company)
- Should be in singular case, no spacing between words, pascal case, and end with
“Controller”. (E.g. ApplicationController, UserController)
Controller Methods
TYPICAL METHOD
VERB URI ROUTE NAME
NAME
GET /photos index() photos.index
GET /photos/create create() photos.create
POST /photos store() photos.store
GET /photos/{photo} show() photos.show
GET /photos/{photo}/edit edit() photos.edit
PUT/PATCH /photos/{photo} update() photos.update
DELETE /photos/{photo} destroy() photos.destroy
Variables – camelCase
- If the variable contains array or collection of multiple items then the variable name
should be in plural (e.g. $mobileUsers = MobileUser::all();)
- Otherwise, it should be singular form (e.g. $mobileUser = MobileUser::first();)
Code Readability
- Be precise and make your code more readable.
Ex:
Common Code Shorter Code
$request->input(‘name’)
$request->name
Request::get(‘name’)
Routes
JQuery
Running command php artisan storage:link will automatically symlink the storage directory into
public to view files publicly, but if files is not required to view but instead to store it, then don’t need
to run the command.
Security
1. Middleware – create admin and superadmin middleware where they can access all.
Path: app/Http/Middleware
Note that it depends on database
structure. In this sample, it uses
user_type, some maybe role_id or
user_access etc.
Using this
Encryption Decryption