Here are some Laravel coding samples to show you how I work. Its not runnable as the files are not connected to each other but it gives you general idea about my coding style.
Ive placed the files in appropriate directories based on laravel 7x
structure (only those dirs that I needed for the samples and not all the dirs of laravel setup are here), therefore please check all dirs for example files. The coding is in php7x
.
Lastly, Ive left notes as comments in each file to let you know whats going on (as much as I could).
-
app\Http\Controllers\lorem\helloWorldOpr.php
The example controller ive got here is a form processor that doesAdd
,Edit
,Clone
as well as uses a 3rd party vendor togenerate pdf
and then alsoemails the pdf as an attachment
. This ive done to show you the deep extend of things we can do with a form in laravel with much ease. -
app\Console\Kernel.php
This shows how I run various schedules and jobs behind the scene without user interaction. -
app\Jobs\TestJob1.php
An example of a Job that is pulls data from a 3rd party API and after some processing saves that data into an sql database. -
app\Mail\testMailClass.php
Mail object used to customize emails and assign templates. -
app\Models\Temp_val.php
Example of a Model that caches results for optimized performance. -
resources\views\lorem\helloWorldOpr.blade.php
Example of a view using blade and js. -
routes\web.php
Route file, see how I pass additional params to each route, I catch them in the parent controller via$request->route()->getAction()
. -
app\Http\Abstracts, app\Http\Helpers, app\Models
These folders are not in laravel itself, but ive created them to better oprganize my code. -
Naming conventions:
Usually I do a lot more efforts in naming conventions but in this sample I just wanted to show a bit of logical implementation and so I might have skipped it.
Let me know if you need even more samples for more fun and tricky things I do in laravel.
Generally I use the following convention:
#/
code block heading related to few line(s) of code after//
small hint about the code on the left to this//
also, to comment out few lines of code/* */
to define a whole block (class, method etc) with a formal descriptors/* */
also, to comment out a whole block of code
In this sample, ive done extra extra commenting to tell you whats going on.
Spacing, indentation and commenting are very important to me
https://en.wikipedia.org/wiki/Post/Redirect/Get
This is most important thing to me when it comes to any form processing, so I always implement this.