At Agira, Technology Simplified, Innovation Delivered, and Empowering Business is what we are passionate about. We always strive to build solutions that boost your productivity.

,

10 Essential Laravel 5 Packages developers Should Use

  • By Nithin Kumar C N
  • September 26, 2018
  • 2477 Views

We all knew that Laravel is one of the fast growing PHP frameworks now a days and one of the great advantage of using Laravel packages are that they will allow us to access all the features of the framework that are offered to host the application, including routing, database migrations, tests, views and some other useful features. On this queue, following are some of the most important packages that are supported by Laravel 5 so let’s untie it one by one.

1) Laravel Debugbar

Laravel debugbar is a package that helps users to add a developer toolbar to your application. This package is mainly using for debugging purposes. There are lot of options are available in debugbar. It will mainly helps us to show all the queries that your application has, everything related to the route being called, will show all the templates being rendered as well as all the passed parameters and much more. You can add messages using the Façade (when added) and it will show under ‘Messages’ tab in Laravel debugbar.

Debugbar::info($object);
Debugbar::error('Error!');
Debugbar::warning('Watch out…');
Debugbar::addMessage('Another message', 'mylabel');

 

Best To Read: Best Laravel Security Practices You Must Try It Out!

 

2) Entrust

This package provides a flexible way to add Role-based Permissions to your Laravel 5 application. This package creates four tables: roles table for storing role records, permissions table for storing permission records, role_user table for storing many to many relations between roles and users, permission_role table for storing many to many relations between roles and permissions.

You can create role by following way,

 

$admin = new Role();
$admin->name         = 'admin';
$admin->display_name = 'User Administrator'; // optional
$admin->description  = 'User is allowed to manage and edit other users'; // optional
$admin->save();

 

Let’s check how to assign the roles to the users,

 

user = User::where('username', '=', 'michele')->first();
$user->attachRole($admin);

Now need to give permissions to those created roles,

$createPost = new Permission();
$createPost->name         = 'create-post';
$createPost->display_name = 'Create Posts'; // optional
// Allow a user to...
$createPost->description  = 'create new blog posts'; // optional
$createPost->save();
$admin->attachPermission($createPost);

 

3) 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. We have to run the following command to create the backup:
[code]
php artisan backup : run
[/code]

4) Eloquent-sluggable

We can define slug as a simplified version of a string. Also it will be URL-friendly. What slugging will do is, it will convert string into one case and make it URL-friendly by removing characters like spaces, hyphens and ampersands. Thus we can use the resulting string as an identifier for any particular entity and this package makes our task easier. For example, if you want to make use of the title field on a model with the slug column then follow the below code,

use Cviebrock\EloquentSluggable\Sluggable;
class Post extends Model
{
   use Sluggable;
   /**
    * Return the sluggable configuration array for this model.
    *
    * @return array
    */
   public function sluggable()
   {
       return [
           'slug' => [
               'source' => 'title'
           ]
       ];
   }
}

So after Slugging, now the title will look like this,

$post = new Post([
   'title' => 'My Blog Title',
]);
$post->save();
// $post->slug = "my-blog-post"

 

5) Socialite

Socialite provides the most convenient way to handle OAuth authentication. It enables users to login via some of the most popular social networks and services including Facebook, Twitter, LinkedIn, Google, GitHub and BitBucket. Let us consider how to use github with Socialite.

$user = Socialite::driver('github')->user();
// OAuth Two Providers
$token = $user->token;
$refreshToken = $user->refreshToken; // not always provided
$expiresIn = $user->expiresIn;
// OAuth One Providers
$token = $user->token;
$tokenSecret = $user->tokenSecret;
// All Providers
$user->getId();
$user->getNickname();
$user->getName();
$user->getEmail();
$user->getAvatar();

 

6) Laravel Mix

Laravel Mix provides a clean and rich API for defining webpack build steps for your project. It is the most powerful asset compilation tool available for laravel today. Laravel Mix formerly known as laravel elixir.

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

 

7) Laravel Intervention Image

Intervention is an open source package for laravel for handling images and its functions easily. It is used to resize the image and save the image into the database and also provides an easier way to create,edit and compose images. It will supports common image processing libraries GD Library and Imagick. We can also generate image thumbnail using the intervention package.
In the below link you can see a demo of how the image intervention package will work in laravel
https://youtu.be/OPWAM0aPCvU

8) Artisan View

This Laravel package will add number of view related commands to your application. By using this, user can able to create views using Artisan command.
Use the below command to create a view ‘index.blade.php’ in the default directory
[code]
$ php artisan make:view index
[/code]

9) Maatwebsite Excel

Laravel excel is ideally used to perform the excel operation in laravel. We can generate the excel using the Maatwebsite excel package and also we can name the excel while generating as well as the sheets, the heading and we can also mention the cells for each excel with this package. Not only that, you can also color the excel cells using this package. Here is the simple code for generating the excel.

Excel::create('ExcelName')
   ->sheet('SheetName')                 
       ->with(array('data', 'data'))             
   ->export('xls');

After creating the excel, you can load the excel into the blade as well and to do that, here is a demo,

Excel::loadView('folder.file', array('data'))->export('xls');

 
Now you can view the Excel.

10) NoCaptcha

NoCaptcha is the laravel package for applying Google`s “reCAPTCHA” validation and protecting forms from spamming. But before all, first you need to obtain an API key from the reCaptcha and here is the link for obtaining the API key. https://www.google.com/recaptcha/intro/v3beta.html
And the sample code is below,

// prevent validation error on captcha
NoCaptcha::shouldReceive('verifyResponse')
   ->once()
   ->andReturn(true);
// provide hidden input for your 'required' validation
NoCaptcha::shouldReceive('display')
   ->zeroOrMoreTimes()
   ->andReturn('');

Here we have shared the few laravel packages which we thought its best to share with you all and also there are lot more packages out there in laravel and we’re planning to cover all those packages in our next blog. Now, with these useful Laravel Packages, you can just play with your application so will leave the rest in your hands. Suggest and tell your best laravel packages to the world, the comment box is open for you! Also don’t forget to subscribe us to get the latest updates from diverse technologies.
For any queries reach us via info@agiratech.com.

Nithin Kumar C N

Passionate Senior Software Developer, Expert in PHP, Laravel, JQuery, Angular, With 6 years of experience in web development, he strongly committed himself in delivering authentic applications. Also, he continuously update himself with new technologies & features which drives him to come up with blogs on unique topic.