0% found this document useful (0 votes)
8 views5 pages

Laravel Standard

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views5 pages

Laravel Standard

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Laravel Standard (Web Application) – Nexbridge Technologies Inc’’

FOLDERS AND FILE STRUCTURES

Initially, this is the file and folder structure of newly


pulled project. (Left screenshot)

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

Models Path: app/Models

- 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

Views (Blade file) Path: resources/views

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)

Maximize the usage of yield and extend blade functions.


Controllers Path: app/HTTP/Controllers

- 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’)

return Redirect::back() return back()

$request->has(‘value’) ? $request->value : ‘default’; $request->get(‘value’, ‘default’)

->orderBy(‘age’, ‘desc’) ->latest(‘age’)

->orderBy(‘created_at’, ‘desc’) ->latest()

Use ORM most of the time.


Prefer to use Eloquent over using Query Builder and raw SQL queries.
Always align and format your code to view it clearer.
Logging

- Always use logs, if necessary,


especially on error logs. (e.g.
Log::info($data), Log::error($error)
- Use Log on catch method to detect the
error message (try and catch)

The error message will be found on storage/logs path

Routes

web.php Path: routes/web.php


a. URI – should be in lower case, snake_case, and should be in plural form (e.g.
/photos/create, /photos/{id}
b. Route names – snale_case with dot notation (e.g photos.create)
c. Always use group if the start prefix of URL is the same

d. Always use group if functions are all located on a similar controller

JQuery

- The CRUD ajax has it code in the nexlibrary.js.


- Always recycle your functions, don’t create multiple functions that has the same result.

Saving files on public and storage

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.

Here is the sample code


Let $file is the file that passed on the backend controller,

1. $file->getClientOriginalName() – is getting the filename of the file


2. url('/').'/storage/'.$path_location.$filename – is the directory where the file will be save, it
typically saves on the database
3. $file->storeAs($path_location, $filename, 'public') – is the indication that the file is
stored in public folder.

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.

2. Encryption and Decryption


Some IDs are needed to be encrypted so that it adds more protection, make sure first that
there has an base64 APP_KEY on the .env file.

Using this

Encryption Decryption

You might also like