Laravel is a free and open source PHP framework for creating web applications. At the time of writing, it is undoubtedly the most popular PHP framework. It offers a lot of features such as authentication, routing, model-view-controller architecture, eloquent and much more.

In this article, we will list down the PHP libraries that we can use to extend Laravel. You will be able to add them to your Laravel project very easily. These packages provide great functionality that you will be required to add in various projects.

1. Laravel Debugbar

Laravel Debugbar is a package that allows you to add a developer toolbar to your Laravel application for debugging purposes. Debugbar is updated for Laravel 5, so you can use it easily in your projects. Debugbar gives you a lot of options such as showing debug messages, exceptions, currently used view and its partials, currently used route and all of the database queries that your application does.

// Messages
Debugbar::info($info);
Debugbar::warning($warning);
Debugbar::error($error);

// Measure render time.
start_measure('render','Rendering time');
stop_measure('render');
add_measure('now', LARAVEL_START, microtime(true));

//Exceptions
try{
    throw new Exception('Some Exception');
} catch(Exception $e) {
    Debugbar::addException($e);
}

2. Laravel User Verification

This package allows you to handle user verification and validates email. It generates and stores a verification token for the registered user, sends or queue an email with the verification token link, handles the token verification, set the user as verified. This package also provides an optional isVerified route middleware.

public function register(Request $request)
{
    $this->validator($request->all())->validate();

    $user = $this->create($request->all());

    event(new Registered($user));

    $this->guard()->login($user);

    UserVerification::generate($user);

    UserVerification::send($user, 'My Custom E-mail Subject');

    return $this->registered($request, $user)
        ?: redirect($this->redirectPath());
}

3. Laravel Mix

Laravel Mix provides a clean and rich API for defining webpack build steps for your project. Mix supports several common CSS and JavaScript pre-processors that can be chained together to build your assets through webpack. You can also use Laravel mix in a non-laravel application.

mix.js(['resources/assets/js/app.js', 'resources/assets/js/custom.js'], 'public/js')
   .sass('resources/assets/sass/app.scss', 'public/css');

 4. Laravel IDE Helper

This package does not extend Laravel in any way but it is very useful when developing Laravel applications with IDE’s like PhpStorm. These IDE’s do not type-hint Laravel facades. This package generates a file that your IDE can understand, so it can provide auto-completion. It generates a file based on the files in your project, so it is always up-to-date.

// PhpDoc generation for Laravel facads.
php artisan ide-helper:generate

// Configuring your composer.json to generate and optimize after commit
"scripts":{
    "post-update-cmd": [
        "Illuminate\\Foundation\\ComposerScripts::postUpdate",
        "php artisan ide-helper:generate",
        "php artisan ide-helper:meta",
        "php artisan optimize"
    ]
},

4. Eloquent Sluggable

A slug is a URL-friendly version of a string. Slugging involves converting letters to one case, removing non-URL friendly characters ( accented letters, ampersands) and replacing spaces with hyphens. Output string can then be used as an identifier for a particular resource. This URL is also SEO-friendly. By using this package you can easily create slugs for your models in Laravel.


<?php

namespace App;

use Cviebrock\EloquentSluggable\Sluggable;
use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    use Sluggable;

    protected $fillable = ['title'];

    public function sluggable(): array
    {
        return [
            'slug' => [
                'source' => 'title'
            ]
        ];
    }
}

$post = new Post([
    'title' => "A random Hamza's post"
]);

// $post->slug = "a-random-hamzas-post"

5. Laravel Backup

This Laravel package creates a backup of all of your files in your application. It creates a zip file that contains all files in the directories you specify along with a dump of your database. Backup can be stored on any file-system. To create a backup all you need to do is to run the following command:

php artisan backup:run

6. Laravel Generators Extended

A library by Jeffrey Way that extends the core file generators that are included in Laravel 5. Generators can save you a lot of time when developing your project. It allows you to quickly set up new views, seeds, and much more.

7. Artisan View

This package allows you to create views in your Laravel application through artisan. It adds a number of artisan commands for working with views.

# Create a view 'admin.blade.php' in the default directory
php artisan make:view admin

# Create a view 'admin.blade.php' in a subdirectory 'auth'
php artisan make:view auth.admin

# Create a view with different file extension ('admin.html')
php artisan make:view admin --extension=html

# Extend an existing view
php artisan make:view admin --extends=master

# Add multiple sections to the view
php artisan make:view admin --section=title --section=content

8. Socialite

Socialite provides a very fluent interface to handle OAuth authentication with Facebook, Twitter, Google, LinkedIn, Github and Bitbucket. It handles almost all of the boilerplate for social authentication.

$user = Socialite::driver('github')->user();
// OAuth Two Providers
$token = $user->token;
$refreshToken = $user->refreshToken; // not always provided
$expiresIn = $user->expiresIn;

// All Providers
$user->getId();
$user->getNickname();
$user->getName();
$user->getEmail();
$user->getAvatar();

9. No Captcha

No Captcha is a package for implementing Google reCaptcha validation and protecting forms from spamming. First, you need to obtain a free API key from reCaptcha.

// prevent validation error on captcha
NoCaptcha::shouldReceive('verifyResponse')
    ->once()
    ->andReturn(true);

// POST request, with request body including g-recaptcha-response
$response = $this->json('POST', '/register', [
    'g-recaptcha-response' => '1',
    'name' => 'John',
    'email' => 'john@example.com',
    'password' => '123456',
    'password_confirmation' => '123456',
]);

10. Laravel Permissions

This package allows you to manage user permissions and roles in a database. It is a Laravel 5 package for working with role-based permissions to your project.

use Illuminate\Foundation\Auth\User as Authenticatable;
use Spatie\Permission\Traits\HasRoles;

class User extends Authenticatable
{
    use HasRoles;

    // ...
}

Posted by Hamza Ali

Web Developer, Graphics Designer, and a writing enthusiast.

8 Comments

    1. Yes, I liked it and it’s a great package. I will consider adding it another post. Thanks for pointing it out.

      Reply

  1. You may want to take a look at

    laravel-widgetize

    Reply

    1. Thanks, I will consider adding it another post. There was a typo in your link, I fixed it.

      Reply

  2. I often use laratrust to extend the roles and permissions function.

    https://github.com/santigarcor/laratrust

    Reply

    1. I have moved to Spatie from Laratrust. 😛

      Reply

  3. Laravel has a slug method available: https://laravel.com/docs/5.5/helpers#method-str-slug.
    We don’t need a package for that.

    Reply

    1. This package is not only for creating slugs. We can use it to create URL’s. If two posts have the same name it will append a number to the URL as well. All of this can be done with very minimal configuration. Creating a slug is just one part of this package. Check out its Github repo for further information.

      Reply

Leave a reply

Your email address will not be published. Required fields are marked *