Get "PHP 8 in a Nuthshell" (Now with PHP 8.4)
Amit Merchant

Amit Merchant

A blog on PHP, JavaScript, and more

7 must-have packages for Laravel Developers

Packages are a great way to extend the functionality of your Laravel application. They can be used to add new features, improve existing functionality, or enhance the performance of your application.

So, here are some of my absolute favorite Laravel packages that you can use in almost all of your projects.

Imagine we’re sitting in a cozy café, chatting about the best tools to enhance your Laravel applications. Yeah? Ready? Let’s go!

Laravel Top

Ever wondered how your Laravel app is performing in real time? Laravel Top has got you covered. This nifty package provides real-time insights into your application’s performance. It’s like having a health monitor for your app.

It listens to Laravel events and saves aggregated data to Redis behind the scenes to calculate metrics.

Installation

Install the package via Composer.

composer require leventcz/laravel-top

You should have Redis installed on your system along with php-redis (PHP extension).

sudo apt-get update
sudo apt-get install redis-server

Once done, you can set the following env variables in your .env file (of course, replace the values with your own).

REDIS_CLIENT=phpredis
REDIS_CLUSTER=redis
REDIS_PREFIX=prefix

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
REDIS_DB=0
REDIS_CACHE_DB=1

Usage

Finally, run the php artisan top command in your terminal to see the real-time stats.

laravel-top

→ Learn more: leventcz/laravel-top

Laravel Debugbar

If you’re active in the Laravel community on Twitter or Discord, you may already know about this package. It’s quite popular by word of mouth because of its usefulness. It provides real-time insights into various aspects of your application, such as database queries, routing, views, logs, and exceptions, directly in your browser.

This tool helps you quickly identify and resolve issues, optimize performance, and gain a deeper understanding of your application’s behavior, making it an invaluable resource for Laravel developers seeking to improve efficiency and code quality.

Installation

Install the Laravel Debugbar Package using Composer and publish the service provider.

composer require barryvdh/laravel-debugbar

php artisan vendor:publish --provider="Barryvdh\Debugbar\ServiceProvider"

Once installed, you’ll be able to see the interface shown below where you can view routes, queries made, exceptions, and more.

Laravel Debugbar

→ Learn more: barryvdh/laravel-debugbar

Laravel Wallet

Need to handle virtual wallets or in-app credits? Laravel Wallet is your go-to package. It simplifies managing virtual wallets and financial transactions, making it ideal for apps with virtual currencies or credits.

Installation

To get started with Laravel Wallet, you need to install the package via Composer.

composer require bavix/laravel-wallet
 
php artisan vendor:publish --provider="Bavix\Wallet\WalletServiceProvider"

Laravel Wallet is a powerful and flexible package that simplifies the implementation of digital wallet systems in your Laravel application. By providing a secure and extensible framework for managing user balances and transactions.

Follow the Laravel Wallet documentation for detailed installation instructions.

→ Learn more: bavix/laravel-wallet

Laravel Log Viewer

Laravel Log Viewer is a quite popular package. When it was launched, it was even appreciated by Taylor Otwell himself. Since then, it’s been the first package I install in any project.

Digging through log files can be tedious. Laravel Log Viewer makes it a breeze by providing an easy-to-use interface for viewing and managing logs directly from your application. Install the package, and you’ll get a clean, accessible log viewer right in your app. It’s fantastic for quickly identifying and fixing issues.

Laravel Log Viewer Documentation

Installation

Install the package via Composer and publish the assets.

composer require arcanedev/log-viewer

php artisan log-viewer:publish

Usage

Once installed, the package is now ready to use! Just visit the /log-viewer route in your browser.

Laravel Log Viewer

→ Learn more: opcodesio/log-viewer

Laravel Permissions

I’ve always worked on multi-tenant projects in Laravel that require managing roles and permissions for different levels of users. The Laravel Permissions package by Spatie solves this problem easily. It’s very easy to install and integrate, with handy methods.

Managing user roles and permissions can be complex. Laravel Permissions simplifies this by providing a robust system for handling roles and permissions within your Laravel application.

Installation

Install the package via Composer, publish the provider, and run the migrations.

composer require spatie/laravel-permission

php artisan vendor:publish --provider="Spatie\Permission\PermissionServiceProvider"

php artisan migrate

Usage

Defining roles and permissions

Role::create(['name' => 'admin']);
Permission::create(['name' => 'edit articles']);

Assigning permissions to a role

$role = Role::findByName('admin');
$role->givePermissionTo('edit articles');

→ Learn more: spatie/laravel-permission

Laravel Modules

If you love keeping your codebase organized, Laravel Modules is for you. It allows the creation of modular applications, making it easier to manage and scale your projects. It’s a scalable approach that you can use for your project. If you think that your project can have a lot of modules and each module can expand itself in the future. Then this could be a great decision for you to make.

Installation

Install the package via Composer.

composer require nwidart/laravel-modules

Usage

Now, let me show you an example.

For instance, if you are creating an application to manage e-commerce inventory, you may need to integrate multiple channels in your application. In that case, you can use the modular approach, to keep each of them separate in terms of product management and further API integration.

The app can have the following modules.

  • Amazon
  • WooCommerce
  • Ebay
php artisan module:make Amazon

Working within a module.

php artisan module:use Amazon
php artisan module:make-model AmazonFeedFetchModel

Once a module is created, you can start adding your functionality. For example, you can define routes specific to your module in Modules/<ModuleName>/Routes/web.php and create controllers in Modules/<ModuleName>/Http/Controllers.

→ Learn more: nWidart/laravel-modules

Laravel Media Library

This package is a go-to solution for handling image uploads, video uploads, and just about any type of file upload you can think of. It can associate all sorts of files with Eloquent models. It provides a simple API to work with.

Installation

composer require spatie/laravel-medialibrary

php artisan vendor:publish --provider="Spatie\MediaLibrary\MediaLibraryServiceProvider" --tag="config"

php artisan migrate

Usage

Here’s a quick example of how to use the Laravel Media Library package to associate an image with a model.

$yourModel = YourModel::find(1);

$yourModel->addMedia($pathToFile)->toMediaCollection('images');

→ Learn more: laravel-medialibrary

In closing

There you have it, Laravel enthusiasts! These packages are like secret weapons in your developer toolkit, ready to enhance your Laravel projects effortlessly. Whether you’re optimizing performance with Laravel-top, debugging with Laravel Debugbar, managing virtual wallets with Laravel Wallet, inspecting logs with Laravel Log Viewer, handling permissions with Laravel Permissions, or organizing your code with Laravel Modules, these tools make your development process smoother and more efficient.

They’re bound to save you time and effort, letting you focus more on creating amazing features and less on the nitty-gritty details. Happy coding!

Learn the fundamentals of PHP 8 (including 8.1, 8.2, and 8.3), the latest version of PHP, and how to use it today with my new book PHP 8 in a Nutshell. It's a no-fluff and easy-to-digest guide to the latest features and nitty-gritty details of PHP 8. So, if you're looking for a quick and easy way to PHP 8, this is the book for you.

Like this article?

Buy me a coffee

Meet the author

Gurpreet Kait is a freelance software developer (PHP, JS guy), tech blogger, and a flutist.

Comments?