Laravel Guide

Our Laravel Framework guide. In our best practices we aim to put together all the resources using the Laravel Framework.

  1. New Laravel Project Install
  2. Existing Laravel Project Clone
  3. General PHP Rules
  4. Configuration and view files
  5. Routing
  6. Controllers
  7. Blade Templates
  9. Community Resources

New Laravel Project Install

  1. Download and install Composer- Laravel utlilizes Composer to manage various dependancies. Hence it is important to have composer installed on your machine.

  2. Install Laravel to Composer- Laravel can be called and executed locally on your machine, by running composer global require "laravel/installer". This command creates a new directory allowing for fresh Laravel installs to be specified.

  3. Create new Laravel project- Composer will create a new project with the latest Laravel version currently i.e. 5.7 composer create-project laravel/laravel test

  4. Check to see whether the new project generated successfully then the following changes can be made-

    • php artisan key:generate (encrypt data such as sessions, passwords and tokens),
    • php artisan serve (generate new Local Development Server),
    • Laravel development server started: <>

Existing Laravel Project Clone

  1. Clone the project from GitHub- git clone project-directory-name

  2. Copy .env file on the root folder- If there hasn’t been an existing env file provided, run php artisan key:generate to generate a new .env file. Remember to change the DB_DATABASE, DB_USERNAME and DB_PASSWORD to correspond to your configuration.

  3. Database migrations- A database should have been provided, when the database has been provided or a new one has had to be made run php artisan migrate so that the latest changes to the database have been made.

  4. Check environment setup- By running php artisan serve the environment can be configured to see whether the installation was successful. If not it maybe worth running composer update in the project directory. Laravel development server started: <>

General PHP Rules

The formatting of our code must follow PSR-1 and PSR-2 where appropriate.

Configuration and view files

Configuration files and blade templates must use kebab-case.



Configuration keys must use snake_case.

// config/contact-form.php
return [
    'email_address' => env('PRIMARY_EMAIL_ADDRESS'),


All URLs should have a clear hierarchy:
Route::get('example', '[email protected]')->name('example'); // first-level
Route::get('example/example2', '[email protected]')->name('example2'); // second-level hierarchy
Route::get('example/example2/{id}', '[email protected]')->name('example3'); // third-level hierarchy requiring a parameter
<a href="/example">
    Example 1, first-level hierarchy

<a href="/example/example2">
    Example 2, second-level hierarchy

<a href="/example/example2/{{ $id }}">
    Example 3, third-level hierarchy, must have parameter


Where appropriate keep controllers simple and use the CRUD methods such as (index, create, store, show, edit, update, destroy). These methods can be automatically generated in the terminal by creating a new Resource Controller php artisan make:controller ExampleController --resource.

If you need other methods that follow under the same category, it is best practice to create a new resource Controller or if you need a single function create a Single Action Controller

For example in the below, we could have a Resource Controller with multiple actions or a single Action Controller to handle additional methods

// Default CRUD method Controller example
class CRUDExampleController
    * Show the form for creating a new resource.
    * @return \Illuminate\Http\Response
    public function create()
      return view('view-create-new-model');

    * Store a newly created resource in storage.
    * @param  \Illuminate\Http\Request  $request
    * @return \Illuminate\Http\Response
    public function store(Request $request)
      $record = new Record;
      $record->column1 = $request->column1;
      $record->column2 = $request->column2;

      return response(null, 200);

// Single Action Controller example
class SingleActionExampleController
    * Action title
    * @param  int  $id
    * @return View
    public function __invoke(Model $model)
      return view('view', ['model' => $model]);

Resource Controllers

Resource Controllers have default CRUD functionality as explained earlier, the routes for these functions can found through the terminal command php artisan route:list, in doing so, all routes in the application are listed. To target a Resource Route make sure the Form action/AJAX url matches. Below is an example of targeting some Resource Controller functions (More examples):

// Storing new Data to a Resource Controller
<form method="post" action="{{URL::route('')}}">

// Deleting Data to a Resource Controller
  type: 'DELETE',
  url: '/example/' + id,
  data: {
    "id": id
// Register example Resource Controller routes
Route::resource('example', 'ExamplesController');

php artisan route:list result in terminal for Resource Controller routes:

| METHOD    | URL                    | NAME            | ACTION
|           |                        |                 |      
| POST      | example                |   | App\Http\Controllers\[email protected]  
| GET       | example                | example.index   | App\Http\Controllers\[email protected]  
| GET       | example/create         | example.create  | App\Http\Controllers\[email protected]
| GET       | example/{example}      |    | App\Http\Controllers\[email protected]   
| PUT       | example/{example}      | example.update  | App\Http\Controllers\[email protected]
| DELETE    | example/{example}      | example.destroy | App\Http\Controllers\[email protected]
| GET       | example/{example}/edit | example.edit    | App\Http\Controllers\[email protected]   

Blade Templates

Indent using four spaces.

<a href="/contact-us">
    Contact Us

Don't add spaces after control structures.



If writing clear and concise code as outlined in this guidelines then comments should only assist the reading process:

// Always leave space before a single line

 * Integer posuere erat a ante venenatis dapibus posuere velit aliquet
 * cras justo odio, dapibus ac facilisis in, egestas eget quam
 * aenean lacinia bibendum nulla sed consectetur

For every method should be a comment explaining its use.

Community Resources

What we currently use