Search by

rookiextreme / laravel-toolkit

meorrin555

Wrapper for commonly used code for a much shorter syntax in controllers and such

Package info

github.com/rookiextreme/laravel-toolkit

pkg:composer/rookiextreme/laravel-toolkit

Statistics

Installs: 24

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.1.1 2026-09-15 19:56 UTC

This package is auto-updated.

Last update: 2026-09-15 19:56:42 UTC


README

A collection of reusable Laravel utilities for common development tasks.

⚠️ This package is currently a personal learning project. It is used to learn Composer packages, PHPUnit, package architecture, and Laravel package development while also serving as a reusable toolkit for my own Laravel applications.

Installation

composer require rookiextreme/laravel-toolkit

Usage

DateFormatter

use RookieXtreme\LaravelToolkit\Date\DateFormatter;

$dateFormatter = new DateFormatter();

$dateFormatter->reverse('06-08-2026');
// 2026-08-06

$dateFormatter->regular('2026-08-06');
// 06-08-2026

API Response Helper

Build the payload

use RookieXtreme\LaravelToolkit\Response\ApiResponse;

$apiResponse = new ApiResponse();

//Status can be either 'success' or 'error' only

$payload = $apiResponse->buildMessagePayload('success', 'Some label');
/*
    [
        'status' => 'success',
        'message' => 'Some label'
    ]
*/

$payload = $apiResponse->buildDataPayload('success', ['id' => 1, 'something' => true]);
/*
    [
        'status' => 'success',
        'data' => ['id' => 1, 'something' => true]
    ]
*/

Send payload to build JSON response

$apiResponse->jsonResponse($payload)
//returns Laravel JSON response object

File Upload

The FileUpload feature provides a simple way to upload files with configurable upload options.

The uploaded file must be provided as an Illuminate\Http\UploadedFile object.

Basic Usage

use Illuminate\Http\UploadedFile;
use Rookiextreme\LaravelToolkit\Upload\UploadOptions;

$upload->uploadFileInApp(
    $image,
    'uploads/images',
    new UploadOptions(
        extensions: ['pdf']
    )
);

$image must be an UploadedFile object.

Upload Options

UploadOptions allows you to configure how the file should be uploaded.

class UploadOptions
{
    public function __construct(
        public array $extensions = [],
        public bool $useOriginalName = false,
        public bool $useOriginalNameUnique = false,
        public bool $useRandomIntName = false,
        public int $maxSize = 0,
        public int $minSize = 0,
        public string $destination = 'storage',
        public string $disk = 'public'
    ){}
}
Option Type Default Description
extensions array [] Allowed file extensions.
useOriginalName bool false Saves the file using its original filename.
useOriginalNameUnique bool false Saves the original filename with a random number appended.
useRandomIntName bool false Generates a random integer as the filename.
maxSize int 0 Maximum allowed file size.
minSize int 0 Minimum allowed file size.
destination string 'storage' Determines whether the file is uploaded to storage or public.
disk string 'public' Laravel filesystem disk used when uploading to storage.

Filename Options

Original Filename

new UploadOptions(
    extensions: ['jpg'],
    useOriginalName: true
);

Original Filename with Random Number

new UploadOptions(
    extensions: ['jpg'],
    useOriginalNameUnique: true
);

Example:

profile_48291.jpg

Random Integer Filename

new UploadOptions(
    extensions: ['jpg'],
    useRandomIntName: true
);

Example:

48291.jpg

File Size

Maximum and minimum file sizes can be configured using maxSize and minSize.

new UploadOptions(
    extensions: ['jpg', 'png'],
    maxSize: 2048,
    minSize: 100
);

Destination

By default, files are uploaded to the storage destination.

new UploadOptions(
    extensions: ['pdf']
);

Files can also be uploaded directly to the public directory:

new UploadOptions(
    extensions: ['jpg'],
    destination: 'public'
);

Storage Disk

When using the storage destination, a specific Laravel filesystem disk can be selected.

new UploadOptions(
    extensions: ['pdf'],
    destination: 'storage',
    disk: 'public'
);

Return Value

The upload method returns an array containing the uploaded file's path and filename.

[
    'path' => 'uploads/images',
    'name' => '48291.jpg'
]

Artisan Command

The toolkit:make-mail-job command provides a quick way to generate a predefined mailing job template in the application's app/Jobs directory.

Instead of manually creating and setting up a new queued mailing job every time a new mailing scenario is needed, the command generates the basic job structure automatically. The generated job can then be customized according to the application's requirements.

php artisan toolkit:make-mail-job {filename?}

If no filename is provided, the command will prompt for one. If no value is entered, a default filename with a random number will be generated.

php artisan toolkit:make-mail-job {filename?}

You can provide the filename directly:

php artisan toolkit:make-mail-job RegistrationMailingJob

If no filename is provided, the command will ask for one.

If no value is entered again, a default filename will be generated with a random number, for example:

MailingJob_5832

Mailing Job

A generated mailing job can be dispatched like this:

dispatch(new RegistrationMailingJob(
    type: 'notification',
    to: [
        $user->email => $user->name
    ],
    subject: 'Your Registration Confirmation',
    blade: 'mailing.registration-confirmation',
    data: [
        'user' => $user,
    ],
    attachment: public_path('assets/files/document.pdf'),
));

The data parameter can contain any data required by the mailing job, including arrays, strings, objects, Eloquent models, and other application data.

For example:

data: [
    'user' => $user,
    'registration' => $registration,
    'facility' => $facility,
],

The mailing job is queued and can be customized according to the application's requirements.

QR Code

Provides a simple helper for generating QR codes without repeatedly setting up the QR code library in each Laravel project.

Generate QR Code

$qr = $toolkit->generateQr(
    extension: 'png',
    size: 500,
    value: 'https://example.com'
);

The method returns the generated QR code output.

Generate Base64

Pass true as the fourth argument to return the QR code as a Base64-encoded string:

$qr = $toolkit->generateQr(
    extension: 'png',
    size: 500,
    value: 'https://example.com',
    base64: true
);

This is useful when embedding the QR code directly into an image element.

Using in Blade

When using the Base64 option, the result can be placed directly into an <img> element:

<img src="data:image/png;base64,{{ $toolkit->generateQr(
    'png',
    500,
    'https://example.com',
    true
) }}" alt="QR Code">

You can also generate the QR code in your controller and pass it to the view:

$qr = $toolkit->generateQr(
    'png',
    500,
    'https://example.com',
    true
);

return view('example', compact('qr'));

Then in Blade:

<img src="data:image/png;base64,{{ $qr }}" alt="QR Code">

Parameters

Parameter Type Default Description
$extension string png QR code image format
$size float 500 QR code size
$value mixed null Value to encode into the QR code
$base64 bool false Whether to return the generated QR code as Base64

If no value is provided, the method returns null.

Location Module

The toolkit can install a reusable Country and State location module into your Laravel application.

The installer publishes:

  • Country model
  • State model
  • Country migration
  • State migration
  • Country seeder
  • State seeder

Installation

Run:

php artisan toolkit:install-location

The command will publish the required models, migrations, and seeders into your Laravel application.

After installation, run the migrations:

php artisan migrate

Then run the seeders:

php artisan db:seed --class=CountrySeeder
php artisan db:seed --class=StateSeeder

Or run your application's normal seeding process if the location seeders have been added to DatabaseSeeder.

Published Files

The installer publishes the files into the standard Laravel directories:

app/
└── Models/
    ├── Country.php
    └── State.php

database/
├── migrations/
│   ├── *_create_list_countries_table.php
│   └── *_create_list_states_table.php
└── seeders/
    ├── CountrySeeder.php
    └── StateSeeder.php

The migrations are published with Laravel migration timestamps, with the Country migration ordered before the State migration.

Relationships

A state belongs to a country, while a country can have multiple states.

Example:

$country = Country::find(1);

$country->states;

And:

$state = State::find(1);

$state->country;

The published models are part of your application, so you are free to extend them with additional relationships, scopes, attributes, or application-specific logic.

Features

  • ✅ Date Formatter
  • ✅ API Response Helper
  • ✅ Image Uploader
  • ✅ Predefined Mailing Job Command
  • ✅ QR Code Generator
  • ✅ Location Installer
  • 🚧 More coming soon

Roadmap

  • Date Formatter
  • API Response Helper
  • Image Uploader
  • Predefined Mailing Job Command
  • QR Code Generator
  • Location Installer
  • Model Actions
  • Validation Helpers
  • File Utilities

License

MIT