Packages Posts

Top Laravel packages that you need in 2022

What is Laravel?

Laravel is the most popular PHP framework right now to develop web applications, it offers a very easy environment and services for developers.

In this blog, we are going to know about the packages that we must have to use while developing any laravel application.

Best Laravel Packages

Here we are going to see some best and top laravel packages that will help you to optimize your application performance and it's also very useful while doing the development.

IDE Helper

Github: https://github.com/barryvdh/laravel-ide-helper

It's a very helpful package and saves lots of time for the developer.

It will generate the helper file which enables our IDE to provide accurate autocompletion while doing the development.

Laravel Debugbar

Github : https://github.com/barryvdh/laravel-debugbar

This is very helpful when we have to check the page performance, in sense of how many queries are firing on the specific page? , how many models are loading? etc.

We can show the total processing time of the page, and the query results time too. by using that results we can do some refactor to our code and make our application more optimized.

Spatie Medialibrary

Github : https://github.com/spatie/laravel-medialibrary

This package is very useful when we are doing file uploads. also, it allows us to upload files to the s3 (AWS) very easily by changing just the file system driver.

The main functionality it has is it allows us to associate files with the Eloquent models.

Spatie Role Permission

Github : https://github.com/spatie/laravel-permission

It's 2022 and still, lots of developers are using the custom roles/permissions management. they even didn't familiar that this package have capabilities to manage each role/permissions management with a specific Eloquent model too.

We can assign roles or permissions to the user model or even any model. later we can check it via the middleware that this package is providing.

Ziggy

Github : https://github.com/tighten/ziggy

Before using this package you must need to implement the named routes into your laravel application.

Normally people can just provide a hardcoded URL into the JS file while doing the AJAX calls. But with this package, you can use the route we are using in blade files.

This allows us to use the route() helper method in the JS files.

June 09, 20222 minutesVishal RibdiyaVishal Ribdiya
How To Make a Laravel Application PWA In Few Minutes

Recently, I have created a new package for Laravel Community. it's called Laravel PWA. first of all what is PWA? let me explain a bit more about PWA. PWA means progressive web application. PWA provides a facility to install your web application on mobile and desktop. you don't need to write lots of line code in native platform-specific code.

You can create a PWA site in a few minutes using Laravel PWA.

You can watch the video tutorial as well to install this package.

Step 1:

Install the package by the following command,

composer require ladumor/laravel-pwa

Step 2:

Add Service Provide into app.php config file in provider section. You can skip this step if you installed it in Laravel 6 and more.

Ladumor\LaravelPwa\PWAServiceProvider::class,

Step 3:

Add Facade to app.php config file in aliases section. You can skip this step if you installed it in Laravel 6 and more.

'LaravelPwa' => \Ladumor\LaravelPwa\LaravelPwa::class,

Step 4:

I think installation is done and no need to publish all the assets using the following command,

php artisan laravel-pwa:publish

Step 5:

This step is very important. you published all the assets in the previous step. now, you need to link all the assets in your main blade file. for ex app.blade.php

Add the following code in the root blade file in the header section.

<!-- PWA  -->
<meta name="theme-color" content="#6777ef"/>
<link rel="apple-touch-icon" href="{{ asset('logo.PNG') }}">
<link rel="manifest" href="{{ asset('/manifest.json') }}">

Add following code in root blade file before close the body,

<script src="{{ asset('/sw.js') }}"></script>
<script>
    if (!navigator.serviceWorker.controller) {
        navigator.serviceWorker.register("/sw.js").then(function (reg) {
            console.log("Service worker has been registered for scope: " + reg.scope);
        });
    }
</script>

You should watch this tutorial if you want to set it up manually instead of using this package.

October 08, 20213 minutesShailesh LadumorShailesh Ladumor
How to add project as a library to Android Studio

But if you want to add another project as a library in your application. For that, you need to add that library project to your application as a module dependency.

1. Open Your Project in Android Studio.

2. You will find the two main directory name samples and others.

3. Go to Android Studio and navigate to File -> New -> Import Module -> Select the library path -> Finish.

2021-07-24-60fbb0d6a0a7c

4. Import-Module from Directory.

2021-07-24-60fbb6e95102d

5. Then right-click on the App directory -> Open Module Settings -> Dependencies -> Click on + button inside Declared Dependencies -> Module Dependency -> Select your library -> Ok.

2021-07-24-60fbb90b68dec

2021-07-24-60fbb99dd54e3

Another way to add Module Dependency

  • Open build.gradle Of the main module
dependencies {

implementation project(":sample")

}

There can be a situation when we need to modify the library code according to our requirement then in that case we can follow this method.

July 25, 20212 minutesVivek BeladiyaVivek Beladiya
How to generate User Device API using Laravel One Signal

Generally, we are using a Laravel One Signal package for push notification. if you are planning to use one signal in the mobile application then this package right for you.

Recently, I add a new feature UserDevice. let me explain why I added support for user Device APIs.

We need to create an API to register a device because One Signal sends a push notification using os player id. so, we need to store os_player_id in the backend from the mobile application. So, need to create an API for it.

Now. you can save your time using this package. you can Generate APIs using one artisan command,

php artisan one-signal.userDevice:publish

This command generates the following files,

  • UserDeviceAPIController
  • UserDeviceAPIRepository
  • UserDevice (model)
  • Migration So, everything is ready in minutes and delivered an API on the spot.

Also, do not forget to add the following routes to the api.php file.

use App\Http\Controllers\API\UserDeviceAPIController;

Route::post('user-device/register', [UserDeviceAPIController::class, 'registerDevice']);
Route::get('user-device/{playerId}/update-status', [UserDeviceAPIController::class, 'updateNotificationStatus'])
July 08, 20212 minutesShailesh LadumorShailesh Ladumor
How to setup passwordless Login In Laravel
Parsed in 0.31 ms or 2 times faster

Basically, we set up email/username and password login in all our projects. but, sometimes we need to implement s passwordless login in the laravel application,

First of all, what is passwordless login? passwordless login is an authentication method that allows the user to log in without entering a password.

In this article, I show you how to set up passwordless login laravel step by step.

Step 1:

one great laravel package Laravel Passwordless Login provides the ability to log in without a password.

This package provides a temporary signed URL link that logs in a user, What it does not provide is a way of actually sending the link to the route to the user. This is because I don't want to make any assumptions about how you communicate with your users.

Step 2:

Open the terminal and go to the project directory and fire the following command to install

composer require grosv/laravel-passwordless-login

Step 3:

Configure the following variables in your env file

  LPL_USER_MODEL=App\User
  LPL_REMEMBER_LOGIN=false
  LPL_LOGIN_ROUTE=/magic-login
  LPL_LOGIN_ROUTE_NAME=magic-login
  LPL_LOGIN_ROUTE_EXPIRES=30
  LPL_REDIRECT_ON_LOGIN=/
  LPL_USER_GUARD=web
  LPL_USE_ONCE=false
  LPL_INVALID_SIGNATURE_MESSAGE="Expired or Invalid Link"

Step 4:

Create one function in your login controller. it looks like

use App\User;
use Grosv\LaravelPasswordlessLogin\LoginUrl;

function sendLoginLink(\Request $request)
{
    $user = User::where('email','=', $request->get('email))->first();

    $generator = new LoginUrl($user);
    $url = $generator->generate();

    //OR Use a Facade
    $url = PasswordlessLogin::forUser($user)->generate();

    $data['url'] = $generator->generate();
    $data['user'] = $user;

    Mail::to($user->email)->send(new UserLoginMail($data));

    return back();
}

Step 5:

Set following route in your web.php

Route::post('/user/login', [LoginController::class, 'sendLoginLink'])->name('userLogin');

Step 6:

Create one mailable. you can refer to a doc if not familiar. Also, fire the following command to create a mailable

php artisan make:mail UserLoginMail

Step 7: Create an Email UI as per your requirement.

April 02, 20212 minutesShailesh LadumorShailesh Ladumor
How to implement Mailchimp into Gatsby Site

We have recently developed a site into the gatsby. Basically, the contact us feature is common on all websites. and we are implementing Mailchimp because it's a very popular platform in the email market. So, I will show you how to set up a Mailchimp on the Gatsby site.

Using gatsby-source-mailchimp

Use your Mailchimp API key to download your campaigns into Gatsby’s GraphQL data layer! Install the package by running the following command: npm i gatsby-source-mailchimp --save. How to configure Once the installation is complete, you can now add this plugin to your gatsby-config.js, like so: Configure Mailchimp Key and add this {resolve: gatsby-source-mailchimp} into the plugins array. code looks like,

module.exports = {
  // ...
  plugins: [
    {
      resolve: 'gatsby-source-mailchimp',
      options: {
        // Avoid including your key directly in your file.
        // Instead, opt for adding them to .env files for extra
        // security ;)
        key: 'asd712jdas90122jdas90122jkadsd1-usXX',
        rootURL: 'https://usXX.api.mailchimp.com/3.0',
      },
    },
  ],
  // ...
}

This plugin was made out of a specific necessity, so it doesn't cover all of Mailchimp’s data sources, focusing only on campaigns.

This plugin provides a few options. you can refer here

Using .env variables to hide your key

If you don’t want to attach your API key to the repo, you can easily store it in .env files by doing the following:

Put this in your .env file

MAILCHIMP_KEY = 'asd712jdas90122jdas90122jkadsd1-usXX';

Put this in your gatsby-config.js file

require('dotenv').config({
  path: `.env.${process.env.NODE_ENV}`,
});

module.exports = {
  // ...
  plugins: [
    {
      resolve: 'gatsby-source-mailchimp',
      options: {
        key: process.env.MAILCHIMP_KEY,
        rootURL: '[https://usXX.api.mailchimp.com/3.0',](https://usxx.api.mailchimp.com/3.0%27,)
        // ...
      },
    },
  ],
  // ...
};
October 31, 20202 minutesShailesh LadumorShailesh Ladumor
How to use AdminLTE theme with Laravel Fortify

Recently, the Laravel team announced a Laravel Fortify. A framework agnostic authentication backend for Laravel applications. It provides registration, authentication along with two-factor authentication.

As said above, it is framework agnostic, so it doesn't provide any blade views with it. You can implement views of your choice of the frontend. Blade, Vue, React with Bootstrap or TailwindCSS, or any other CSS framework.

Today we are going to see how we can use Laravel Fortify with one of the most popular Bootstrap 4 theme AdminLTE v3.

We can actually do that in minutes with the package that we already developed called Laravel UI AdminLTE

This package also works with the previous laravel version to have an authentication system with Laravel UI for Laravel Frontend Scaffolding.

Let's see step by step, how we can do that.

Install Packages

Install Laravel Fortify and Laravel UI AdminLTE by the following command,

composer require laravel/fortify infyomlabs/laravel-ui-adminlte

Publish Fortify Resources

This command will publish all required actions in the app/Actions directory along with the Fortify configuration file and migration for two-factor authentication.

php artisan vendor:publish --provider="Laravel\Fortify\FortifyServiceProvider"

Run Migrations

Then run migrations,

php artisan migrate

Add Fortify Service Provider

Next step, add published FortifyServiceProvider to config/app.php

Run AdminLTE Fortify Command

Run the following command,

php artisan ui adminlte-fortify --auth

Install Node Modules and Run a Build

As a next step, install required npm modules and run a build,

npm install && npm run dev

And we are done. Now visit the home page and you should be able to see the full authentication system working including,

Login Registration Forgot Password Reset Password Home page

Laravel AdminLTE UI also provides a starting layout with a sidebar menu and header once you login. so you are all set to go.

June 27, 20202 minutesMitul GolakiyaMitul Golakiya
Laravel Packages we use everyday at InfyOm

Lots of people ask me frequently, "Which are the laravel packages that you use in almost all projects?" when we meet in Meetup or any other events regardless of its online or physical events.

Let me describe today some of the packages that we almost use in all of the projects.

We have been working in Laravel for almost 7+ years and in these years we have used lots of packages, some from the community and some of our own.

I am categorizing these into 2 categories.

  1. Most used packages
  2. Common Need/Functionality specific packages

Most used packages

These are the packages which must be included in all of our projects. No Excuses.

barryvdh/laravel-ide-helper

Laravel exposes a lot of magic methods and properties. IDE Helper is a very good package when it comes to auto-complete those properties and methods. Even it does an amazing job while refactoring properties or methods of the model.

barryvdh/laravel-debugbar

The second one is from the same author, debugbar helps to debug the request in terms of the number of queries fired, time taken by each query, number models retrieved from db, time taken by each request, and much more.

imanghafoori/laravel-microscope

Laravel Microscope improves the readability of your code. Early returns, unnecessary else statements, and many more. so your code looks clean and efficient in terms of execution as well.

beyondcode/laravel-query-detector

One of the problems that we face is, missing eager loading. In ongoing development, sometimes we add relationships objects in the loops, and then laravel fires tons of queries to the database. Laravel Query Detector detects that and gives a warning while developing the environment.

InfyOmLabs/laravel-generator

No application can be ever built without a few CRUDs. CRUDs are essential in almost all web applications. Also, APIs of CRUDs are essential while building a backend for Mobile or Frontend apps. Laravel Generator is our own developed package that we use in all of the applications to make the CRUD building process faster. It can be used with two themes right now, AdminLTE and CoreUI. But it's also frontend framework agnostic.

Common Need/Functionality specific packages

These are the packages that are used when we particularly need that kind of functionality in the application.

Will keep this list updating.

September 11, 20202 minutesMitul GolakiyaMitul Golakiya