How Can Setup Microservices-in-laravel

Microservice

Microservice is a collection of freely deployable services. It is an approach to building application software as a collection of independently deployable, compact, modular services. Herein, each service executes a different operation and interacts with one another via a simple, well-defined interface API.

Why do we need Microservice ?

The 3 prime reasons that modern enterprises need microservice architecture are:
● To defend against a failure of traffic or performance surge.
● To scale graciously
● To reduce the number of individuals engaging in each codebase.

How Can Setup Microservices ?

https://www.scmgalaxy.com/tutorials/how-to-create-new-microservices-in-laravel-framework/

First project

Step-1 Install Project

Step-2 Go to In project

Step-3 composer require laravel/passport

—— composer require laravel/passport=~7.5.0 (For Laravel version 5.8)

Step-4
config/app.php in providers

Laravel\Passport\PassportServiceProvider::class,

Step-5
Set database from .env file
php artisan migrate

composer require lcobucci/jwt=3.3.3

==============================================

Step-6
First open “App\User”

replace from User extents –

in top – use Laravel\Passport\HasApiTokens;

use Illuminate\Notifications\Notifiable;

class User extends Authenticatable
{
use HasApiTokens, Notifiable;

}

Step-8
app/providers/AuthServiceProvider.php

In top – use Laravel\Passport\Passport;

in function boot()- Passport::routes();

Step-9
config/auth.php of api’drivers (Token will be replace)

‘driver’ => ‘passport’,

Step-10
Route/api.php

Route::get(‘/file_name’, ‘FileController@index’);

If Require then———————

install guzzle pakages-

    composer require guzzlehttp/guzzle~6.5.0 

If Require then————

app/Http/Kernel.php

‘client_credentials’ => \Laravel\Passport\Http\Middleware\CheckClientCredentials::class,

====================================================================================================================================

Second Project=====

Step-1 Install Project

Step-2 Go to In project

Step-3 composer require laravel/passport

—— composer require laravel/passport=~7.5.0 (For Laravel version 5.8)

Step-4
config/app.php in providers

Laravel\Passport\PassportServiceProvider::class,

Step-5
set database from .env file

php artisan migrate

composer require lcobucci/jwt=3.3.3

Step-6
php artisan passport:install

    and set client_credentials in first project
    --------------------------------------------

==============================================

Step-7
First open “App\User”

replace from User extents –

in top – use Laravel\Passport\HasApiTokens;

use Illuminate\Notifications\Notifiable;

class User extends Authenticatable
{
use HasApiTokens, Notifiable;

}

Step-8
app/providers/AuthServiceProvider.php

In top – use Laravel\Passport\Passport;

in function boot()- Passport::routes();

Step-9
config/auth.php of api’drivers (Token will be replace)

‘driver’ => ‘passport’,

Step-10
Route/api.php

Route::get(‘/file_name’,’FileController@index’);

If Require then———————

install guzzle pakages-

    composer require guzzlehttp/guzzle~6.5.0 

If Require then————

app/Http/Kernel.php

‘client_credentials’ => \Laravel\Passport\Http\Middleware\CheckClientCredentials::class,

==========================================================================================

when we create microservice we must do one thing,that env name app.php shold be same
for Example-

in env

ADD_STUDENT_DATA_URL=/api/add_studentDetails

in app.php

‘ADD_STUDENT_DATA_URL’ => env(‘ADD_STUDENT_DATA_URL’, ‘not found in .env file’),

===================================================================================================
==================================================================================================

In Client Microservice

============================================

Add Microservice Controller

class MicroserviceController extends Controller
{


private static function getCategoryAccessToken() {
    Log::info('In MicroserviceController ->getCategoryAccessToken()');
    try {
        Log::info('CRUD_M_BASE_URL:'. Config::get('app.CRUD_M_BASE_URL'));
        Log::info('CRUD_M_GRANT_TYPE: ' . Config::get('app.CRUD_M_GRANT_TYPE'));
        Log::info('CRUD_M_OAUTH_TOKEN_URL: ' . Config::get('app.CRUD_M_OAUTH_TOKEN_URL'));
        Log::info('CRUD_M_CLIENT_SECRET: ' . Config::get('app.CRUD_M_CLIENT_SECRET'));
        Log::info('Getting the token!');
        $http = new Client(); //GuzzleHttp\Client
        Log::info('after client the token!');
        Log::info('before  post client the token!');
        $response = $http->post(
            'http://ajaxwithjquery/crud_in_ajax/oauth/token',
            [
                'form_params' => [
                    'grant_type' => Config::get('app.CRUD_M_GRANT_TYPE'),
                    'client_id' => Config::get('app.CRUD_M_CLIENT_ID'),
                    'client_secret' => Config::get('app.CRUD_M_CLIENT_SECRET'),
                    'redirect_uri' => '',
                ],
            ]
        );
        Log::info('after  post client the token!');
        $array = $response->getBody()->getContents();
        $json = json_decode($array, true);
        $collection = collect($json);
        $access_token = $collection->get('access_token');
        Log::info('Got the token!');
        return $access_token;
    } catch (RequestException $e) {
        Log::info('There is some exception in MicroserviceController ->getCategoryAccessToken()');
        return $e->getResponse()->getStatusCode() . ': ' . $e->getMessage();
    }
}

Related Posts

The Complete SEO Playbook for AI Guest Post Generation and Publishing

Introduction Search engine optimization relies heavily on authority, relevance, and trust. While search algorithms continually evolve, securing high-quality backlinks through strategic content placement remains a foundational ranking…

Read More

Top Digital Marketing Workflow Management Tools for Agencies

Introduction Managing a modern digital marketing stack often feels like juggling dozens of disconnected software subscriptions. Marketing managers, agency owners, and SEO specialists frequently find themselves jumping…

Read More

AI Prompt Management Tools: From Basic Prompts to High-Value Digital Assets

Generative artificial intelligence has fundamentally altered how modern enterprises, creative teams, and technical engineers operate. However, as organizations increase their reliance on large language models (LLMs), a…

Read More

Automated Payment Management Software for Modern Enterprises

Finance operations form the backbone of every enterprise, yet many organizations still struggle with fragmented billing tools, delayed collections, and manual reconciliation. Relying on spreadsheets and disconnected…

Read More

The Complete Guide to Choosing the Best Vehicle Rental Management Software

INTRODUCTION Managing a vehicle rental business manually through spreadsheets, paper ledgers, or messaging apps creates significant operational friction. Rental agency owners face recurring challenges including double bookings,…

Read More

The Ultimate Guide to Predictive Alerts and Data Observability

Introduction In modern data-driven enterprises, data pipelines serve as the central circulatory system of business intelligence, operational analytics, machine learning platforms, and executive decision-making. However, as data…

Read More