Skip to content

Laravel coding examples to show you how I work

Notifications You must be signed in to change notification settings

Rah1x/laravel-examples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

laravel Examples

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

Example work in this sample:

  1. app\Http\Controllers\lorem\helloWorldOpr.php
    The example controller ive got here is a form processor that does Add, Edit, Clone as well as uses a 3rd party vendor to generate pdf and then also emails 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.

  2. app\Console\Kernel.php
    This shows how I run various schedules and jobs behind the scene without user interaction.

  3. 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.

  4. app\Mail\testMailClass.php
    Mail object used to customize emails and assign templates.

  5. app\Models\Temp_val.php
    Example of a Model that caches results for optimized performance.

  6. resources\views\lorem\helloWorldOpr.blade.php
    Example of a view using blade and js.

  7. 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().

  8. app\Http\Abstracts, app\Http\Helpers, app\Models
    These folders are not in laravel itself, but ive created them to better oprganize my code.

  9. 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.

Commenting:

Generally I use the following convention:

  1. #/ code block heading related to few line(s) of code after
  2. // small hint about the code on the left to this
  3. // also, to comment out few lines of code
  4. /* */ to define a whole block (class, method etc) with a formal descriptors
  5. /* */ also, to comment out a whole block of code

In this sample, ive done extra extra commenting to tell you whats going on.

Spacing:

Spacing, indentation and commenting are very important to me

Design pattern for CRUD Operation:

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.

About

Laravel coding examples to show you how I work

Resources

Stars

Watchers

Forks