Skip to content

Latest commit

 

History

History
99 lines (75 loc) · 2.95 KB

README.md

File metadata and controls

99 lines (75 loc) · 2.95 KB

Laravel Extras

GitHub tag (latest by date)
This lightweight package is designed to add support for various (non-default) Laravel conventions.

Available Options:

Installation

  1. Add the following to the composer.json file at the root of your project:
"repositories": [
    {
        "type": "vcs",
        "url": "https://github.com/jeremy-langevin-twc/jl-laravel-extras"
    }
]

Or add the inner object to your repositories array if one already exists.

  1. Install the package with composer:
composer require jl-twc/jl-laravel-extras 

Enum

Generation:

php artisan make:enum ENUM_NAME

Extending the Enum class is a great way to define constants that can be used acrost your application. Doing so allows you to modify the value of a constant in one location, while seeing the same value change throughout the app.

ex.

<?php

namespace App\Enum;

class Criticality extends Enum
{
    const LOW = 'Low';
    const MEDIUM = 'Medium';
    const HIGH = 'High';
}

Referencing values from your Enum throughout your application is simple:

use App\Enum\Criticality;

$asset->criticality = Criticality::LOW;

Enums can be used in request validation, conditional statements, setting model values and more. To explore the methods available with the Enum class, take a look inside the base Enum.php file of this package.


Repository

Generation:

php artisan make:repository REPOSITORY_NAME

Repositories are a great place to store business logic. For example, using methods of a Repository inside of a Controller is a great way to keep your Controllers lean.

If you want to learn more about the Laravel Repository pattern, check out this article.


Services

Generation:

php artisan make:service SERVICE_NAME

Similar to Repositories, Services allow you to break sets of code out into separate files, where they can be referenced later. How/if you use them is up to personal preference. Check out this article for one example on how to use Laravel Services.


Advanced Command

Generation:

php artisan make:advanced-command COMMAND_NAME

The advanced command is a work-in-progress take on the traditional Console command generated by Laravel.

In particular, this custom command adds:

  • Processing time down to milliseconds logged to the terminal
  • A baseQuery function, which allows you to define the query (if applicable) that is used in your command
  • A progress bar, which has a default size of the length of the results from your base query
  • Optional DB transaction / rollback calls to test your command without changing your database.