InfyOm Blog

latest-post

Last week, we run into a problem for one of the large Gatsby + ReactJS + Laravel projects in hosting which is hosted with Apache Webserver on Amazon AWS EC2. The problem we were facing was, for some reason, when we reload the Gatsby website, it was giving a 404 error page.

If you open a home page and then a normal visit then the website will fully function, but if you reload the page then it gives an error. And we found it happens when we are using Dynamic routing of React Route in Gatsby as per show in Gatsby documentation here.

Also, what we found, if we test the website build with gatsby serve then it works fine. But while using Apache, it behaves differently and we found that this problem has been faced by lots of people over the internet.

So what we came up with is, we used gatsby serve with an apache proxy. Here is how we did it,

Step 1 - Setup Project

As a first step, clone the project on the server and run a command, gatsby build to create a gatsby build.

Step 2 - Setup PM2 for Gatsby Serve

The next step that we need to do is run gatsby serve. But as you know, we can not run this command directly via console, because as you exit from the console, the command will be terminated.

So we will be using pm2 package, a NodeJS utility that is used to run nodejs apps.

For that, we will need to install pm2 globally. Run the following command to install it,

npm install pm2 -g

You can find other installation ways here if you need.

Once the installation has been done, let's run the gatsby serve command via pm2. For that run the following command from the gatsby project folder,

pm2 start gatsby --name my-web-app -- serve

where my-web-app you can replace with the name of your app.

Once, it's running, try to test it, if it's working correctly by opening the URL http://your-ip-address:9000/. Make sure, port 9000 is opened on your server for traffic.

Step 3 - Configure Apache

Once, gatsby serve is working and tested. The next step is to configure apache to proxy all port 80 traffic to port 9000.

For that, edit your apache conf file (or virtual host conf file), and add the following lines (or configure it to something like the following),

<VirtualHost *:80>
        ServerName my-web-app.infyom.com

        ServerAdmin webmaster@infyom.com

        ProxyRequests On
        ProxyPass / http://localhost:9000/
        ProxyPassReverse / http://localhost:9000/

        ErrorLog ${APACHE_LOG_DIR}/my-web-app.infyom.com.error.log
        CustomLog ${APACHE_LOG_DIR}/my-web-app.log combined

        ......
        # any other options below as per your need
        ......
</VirtualHost>

The next step you need to do is restart your apache server by,

sudo service apache2 restart

And then you can just open the URL https://my-web-app.infyom.com and it should work fine.

Bonus

New Deployment

Whenever you deploy a new code, you again need to run gatsby build and then pm2 restart my-web-app. Then only it will take new changes.

Troubleshooting

Sometimes, we found that we need to restart apache as well after the new deployment. so if you run into any trouble, then make sure to restart apache as well and it should solve the problem.

I hope it may help you to resolve your 404 problem.

July 16, 20213 minutesuserMitul Golakiya

Posts

post

Laravel Debugbar is a great package to debug laravel applications while development. But it's not just limited to debugging. You can use it to optimize the performance of your app a lot as well. Like,

  • number of models loaded in a memory
  • number of queries fired with timing
  • memory used and more.

In short, we can have a complete view of what's going on in each request.

But the less known and use feature it gives is the Timeline tab. Where you can see how much time is taken for each request. And more than that, how much time Laravel took to boot up and how much time our other code has taken. Check the below screenshot.

Timeline

Recently we came to the case, where one of our consultation clients' CRM application was taking too much time on the first load. Their developers were not able to spot a problem. They checked queries and other stuff which looked completely good. so we were not sure where the time has been spent by the application.

That's were debugbar came to rescue us. We used its measure function facility by which we can measure the time spent in each of the function wherever we want to use. It gives simply two functions startMeasure and stopMeasure to measure the time spent between these two statements.

so we can put startMeasure in the staring of function and put stopMeasure at the end of the function which will render something like this in the timeline tab.

public function searchClients($department)
{
    \Debugbar::startMeasure("searchClients");

    // logic here

    \Debugbar::stopMeasure("searchClients");

    return $result;
}

Once we put this, we get a time that searchClients is taking. Check the screenshot below,

Timeline

Hope this can help you to figure out what piece of code is taking the time and you can optimize it.

Happy Optimizing :)

August 22, 20201 minuteauthorMitul Golakiya
post
Software testing is a process of checking and validating the functionality of an application to determine if it meets specified requirements. It is about finding application faults and verifying where the application is operating according to the end-user needs.

Important Software Testing Techniques:-

  • Boundary Value Analysis (BVA)
  • Equivalence Class Partitioning
  • Decision Table based testing.
  • State Transition
  • Error Guessing
  • Boundary Value Analysis (BVA)
  1. The marginal cost assessment is based entirely on trying the boundaries between partitions. It includes maximum, minimum, internal or external barriers, typical values, and error values. It is generally seen that numerous errors occur at the obstacles of the defined input values as opposed to the center.
  2. It is also known as BVA and offers a selection of test entities that train limit values. This black container test method improves equivalence partitioning. This software program trying one approach is based on the principle that if a machine works well for these exact values, it will paint error-free for all values that are between the two limits.
Let's see one example:

Input condition is valid between 1 and 10 Boundary values 0,1,2 and 9,10,11

Equivalence Class Partitioning

The equal class phase lets you divide a hard and fast of check states into separate sections which are taken into consideration identical. The equal class division software program test technique breaks the input area of a program into a class of information, so a test case has to be designed.

Let’s see one example:

Input conditions are valid between

1 to 10 and 20 to 30

Hence, there are five equivalence classes

--- to 0 (invalid)

1 to 10 (valid)

11 to 19 (invalid)

20 to 30 (valid)

31 to --- (invalid)

You select values from each class, i.e.,

-2, 3, 15, 25, 45

Decision Table Based Testing

The decision table is known as the cause and effect table. This testing technique is suitable for input features that have a logical relationship between inputs. In this technique, combinations of inputs are processed. In order to identify the test case with the decision table, it is necessary to consider the terms, actions, and procedures. Conditions are taken as input and actions as output.

Testing Using The Decision Table In The Login Form


CONDITIONS CASE 1 CASE 2 CASE 3 CASE 3
| EMAIL  | F  | T  | F  | T
| PASSWORD  | F  | F  | T  | T
| OUTPUT  | ERROR  | ERROR  | ERROR  | HOME SCREEN

CASE 1: Email And Password Wrong: Error Message Displayed.

CASE 2: Email True And Password Wrong, Error Message Displayed.

CASE 3: Email Wrong And Password True, Error Message Displayed.

CASE 4: Email And Password True, Redirect to Home screen

State Transition Testing Technique

In-State Transition technique changes in input conditions change the state of the Application Under Test (AUT). This testing technique allows the tester to test the behavior of an AUT. The tester can perform this action by entering various input conditions in a sequence. In-State transition technique, the testing team provides positive as well as negative input test values for evaluating the system behavior.

Presently We Make A Diagram For Forgot Password/OTP Proces

  1. First Enter Right Number In This Text Box and Click RESET PASSWORD Button. One OTP Comes On Mobile Number.
  2. To reset the secret word should experience the "OTP" framework. The first run through the client enters the right "OTP", they will be permitted to go to the secret phrase change page.
  3. In the event that the client enters mistaken "OTP" unexpectedly and second, the framework will request the third time "OTP" is entered.
  4. In the event that "OTP" is valid, it will be permitted to go to the secret phrase change page, in any case, if the OTP is off base the third time, Error Message Displayed Like "Your OTP has been expired!!".
State Transition Table


ATTEMPT CORRECT PIN INCORRECT PIN
| [B1] Start  | B5  | B2
| [B2] First attempt  | B5  | B3
| [B3] Second attempt  | B5  | B4
| [B4] third attempt  | B5  | B4
| [B5] Access granted  | -  | -
| [B6] Account blocked  | -  | -
Error Guessing Technique

Error guessing is a software testing technique based on guessing the error that can appear in the code. The technique relies heavily on experience, with the test analysts using their experience to guess the problematic part of the test application. Therefore, test analysts need to be competent and experienced in order to better guess errors. The technique counts a list of possible errors or error-prone situations. Then the tester writes a test case to uncover these errors. To design test cases based on this software testing technique, the analyst can use the experience to identify the conditions.

This technique can be used at any level of testing and for testing the common mistakes like:

  • Divide by zero
  • Inserting blanks in text fields
  • Pressing the enter button without entering values
  • Uploading files that exceed the maximum limits
  • Exception null pointer.
  • Invalid parameters
Let’s see one example:

Suppose there is a requirement that the phone number be numeric and not less than 10 characters. And the software application has a phone number.

The following are the error estimation techniques:

  1. What will be the result if the cellphone number is left blank?
  2. What is the result if a character other than a digit is entered?
  3. What is the result if fewer than 10 digits are entered?
August 22, 20204 minutesauthorBhumi Khimani
post
We work on projects with the admin panel every day. In which we mostly use data tables and we need to delete the record from the data table without page refresh.

So, today I will show you how to extract a record using Ajax. It's very easy to integrate.

Let take one example. I have a Category data table and I want to delete one category from the table without refresh the page. now, what am I doing for that? first of all, I add a class for the listen to a click event into the delete button and it's says delete-btn. 

See the following image for where I added a class.

I used SweetAlert for the confirmation popup. let add sweet alert's CSN into the index.blade.php.

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.min.js"></script>
let's declare routes of the delete record.

<script>
       let categoryUrl = '{{route('categories.index')}}';
</script>
next steps, I going to listen to the click event of the delete button. one more thing does not forget to add the record id into the data attribute to the delete button. see the above image for it. I highlighted with a yellow line.

So the general practices we use in Laravel is to write the following code to listen to a click event and delete a record,

$(document).on('click', '.delete-btn', function (event) {
            const id = $(event.currentTarget).data('id');
            swal({
                    title: 'Delete !',
                    text: 'Are you sure you want to delete this Category" ?',
                    type: 'warning',
                    showCancelButton: true,
                    closeOnConfirm: false,
                    showLoaderOnConfirm: true,
                    confirmButtonColor: '#5cb85c',
                    cancelButtonColor: '#d33',
                    cancelButtonText: 'No',
                    confirmButtonText: 'Yes',
                },
                function () {
                    $.ajax({
                url: categoryUrl + '/' + id,
                type: 'DELETE',
                DataType: 'json',
                data:{"_token": "{{ csrf_token() }}"},
                success: function(response){
                    swal({
                                title: 'Deleted!',
                                text: 'Category has been deleted.',
                                type: 'success',
                                timer: 2000,
                            });
                    $('#categoryTbl').DataTable().ajax.reload(null, false);
                },
                error: function(error){
                    swal({
                                title: 'Error!',
                                text: error.responseJSON.message,
                                type: 'error',
                                timer: 5000,
                            })    
                }
            });
                });
        });
Now we are done with the front-end side and need to look into it backend side. 

Let's declare the destroy method into the category Controller. I hope are you generate crud with InfyOm Laravel Generator. so, the Destroy method and routes are there. if not please create a route. if the destroy method is there then need to change the response of that method.

The destroy method code looks like,

 public function destroy($id)
    {
        $category = $this->categoryRepository->find($id);

        if (empty($category)) {
            Flash::error('Category not found');

            return $this->sendError('Category not found.');
        }

        $this->categoryRepository->delete($id);

        return $this->sendSuccess('Category deleted successfully.');
    }
Now we are done. the video tutorial also available here

August 19, 20202 minutesauthorShailesh Ladumor
post
  • Developer use API calling retrofit, volley JSON or other tools but API response check-in postman time confusion how to creating this response model class
  • So a friend in this topic I will try your confusion remove flow below all steps and 5 min inner creating a wonderful model class
Step: 1 Android studio in install "RoboPOJOGenerator"

  • Location in the android studio:
  1. Open android studio
  2. Go to File
  3. Go to Setting
  4. Click plugin
  • check the below image && click and install RoboPOJOGenerator then your android studio restart
Step: 2 How to open RoboPOJOGenerator

  1. Open android studio
  2. Go to File
  3. Select directory below the image in showing related select any one directory
  4. Right-click - select New - then below showing "RoboPOJOGenerator"
Step: 3 How to add postman response

  1. Postman response copy
  2. Paste this response in "RoboPOJOGenerator" in one black color dialog showing in android studio
  3. Left top side one cursor visible on this area in paste this response
  4. Select "GSON" option in "RoboPOJOGenerator"
  5. Last click generate button after a few moments your model class is ready
August 15, 20201 minuteauthorPankaj Valani
post

Recently, we have started working on one CRM System for client, where we offer a user to create an account and then can upload his excel file of Contracts and we will create contracts in the database, and then these contracts will be emailed to both the parties of the contract.

For this, the functionality we want is, we do not let users wait to do these all things, because this process may take longer based on the number of records the user has. Also, this process contains lots of computation like,

  1. Upload an Excel file
  2. Do field mappings
  3. Validate the record of contract
  4. Create a contract in the database along with all other information
  5. Create a PDF of contract (which take significant time)
  6. Email that PDF to both the parties.

Just imagine, if the user has uploaded a file with 10K records in a file it will take an hour to do this in a single process.

Here is where we used the Laravel Jobs & Queues where we can let use relax and we do our processing in backend with multiple Jobs running at the same time.

So we came up with architecture with Several Jobs in place with the following things in mind.

  1. We will have multiple Jobs to perform multiple things to have SRP (Single Responsibility Principle)
  2. When the one Job completes its duty, it will dispatch the next Job with the data that next job needs.
  3. The next job will do that same till the process ends

Another advantage we got here is, we can execute different jobs on different machines/servers based on the resources required. For e.g. We run a Job of Creating PDF on a powerful machine then sending an email.

Also, we can set different priorities for different Job Listeners. For e.g. Sending an Email Job will have a lower priority than others.

So here is the architecture that we came up with and used. I tried to architect the Jobs structure only and haven't mentioned small details of updating and creating records.

Implementing Efficient and Fast Data Import with Laravel Jobs & Queues

Hope it will help you to architect you a better Jobs and Queues architecture where you need to perform multiple things on the backend and do not let your users wait to finish those long-running processes.

Happy & Safe Queuing. :)

August 14, 20202 minutesauthorMitul Golakiya
post

Step:1 Create a new artboard

Create new art board fill property width 1920 hight 1080 resolution 75px/inch color mode RGb-8bit background white.

Step:2 Select Add a layer style

Click the lock icon to unlock the background and double click it to open click gradient overlay and the gradient bar.

Click the black & white thumbnail in the lower-left step click the color box and pick a soft color that works with your subject.

Step:3 Set Image In artboard

Press v on your keyboard drag the photo onto the keyboard to reposition it just drag it.



Once you're happy with its size and position press enter or return next we'll septate the subject from its background by making a selection around the subject. there are many ways to do this but for this example, I'll use the quick selection tool if you're using

Step:4 Crop as a requirement

This tool as well makes it's radius anywhere between 5 and 10 pixels drag the tool over the inside of your subjective selection



Step:5 Select Refine edge

Those areas to refine the selection edge click refine the edge and check smart radius this detects smooth and hard edge drags the radius a little bit to the right to adjust the size of your project make sure.

The caps lock key is off and press the right or left bracket key on your keyboard drag the brush cover all soft edges like air and press OK.



Step:6 Add Drip image

How to hook it to a new layer with a layer mask open the background.

Ctrl-click the dripping photo to make a selection make the original subject photoactive and press the delete icon on your keyboard click eye ball to hide the dripping pattern then be selected by pressing Ctrl+D.



Step:7 Add Brush Style

Click the new layer icon to make a new layer drag it below your subject.



Set open brush tool and brush picker take this flat seven board number 504 for brush download the splatter brush.



Step:8 Add Effect as per your Requirement

Make the subject layer active and open layer style window click drop shadow the blend mode is linear burn the color is black and the opacity is 100% the angle is 90 degrees and check the use global light.

The distance is 5 pixels the spread is 0% and the size is 0 pixels the contour is linear and the subject is ready



August 11, 20202 minutesauthorKishan Savaliya
post
Laravel Livewire is used to build dynamic web pages that work without ajax or any javascript code. we can build dynamic components with livewire with less code and more functionalities.

I hope this basic introduction will be enough to start laravel livewire.

Now let's move to installation steps, and I hope you already have setup your laravel project.

Install Livewire

 composer require livewire/livewire

Include the javascript and styles (On your master blade file)

  ...
     @livewireStyles
  </head>
  <body>
  ...

     @livewireScripts
  </body>
  </html>

Create Your Component

Here we are going to create a component to create a summation of 2 values without hitting any buttons, it will do a summation of 2 values as you type in text boxes.

Now let's create our component by hitting the following command :

php artisan make:livewire Summation

it will create 2 files as shown below:

// app/Http/Livewire/Summation/php
namespace App\Http\Livewire;

use Livewire\Component;

class Summation extends Component
{
    public function render()
    {
        return view('livewire.summation');
    } 
}

// resources/views/livewire/summation.blade.php
<div>
    ...
</div>

Include the component

Include created component to your view where you want to show.

 <head>
    ...
    @livewireStyles
 </head>
 <body>
    <livewire:summation />

    ...

    @livewireScripts
 </body>
 </html>

Now let's first do a change in our livewire component Summation.php

namespace App\Http\Livewire;

use Livewire\Component;

class Summation extends Component
{ 
   public $value1 = 0;
   public $value2 = 0;
   public $sum = 0;

   public function mount()
   {
      $this->sum = 0;
   }

   public function render()
   {
      $this->sum = $this->value1 + $this->value2;

      return view('livewire.summation');
   }
 }

Here we have to take 2 public properties value1, value2 and sum. and in mount method (which will be called when the page is load the first time) I have replaced the sum property value to 0.

And In the render method, I have done a summation of the 2 public property values. which will be directly accessed values of input from blade files directly here. but how ?? we will see soon.

Now let's change the livewire blade component.

  <div>
   <input type="text" class="" wire:model="value1">

    <input type="text" class="" wire:model="value2">

    <input type="text" disabled wire:model="sum">
  </div>

Here we have bind all properties by using wire:model. so as we will type in input box 1 it will be directly accessed by $value1 into the component.

and the property $sum will be changed as we change the input box values.

So that's how cool livewire is. you can create different dynamic components as you need by using livewire.

Stay tuned to read more interesting posts of a livewire.

August 07, 20202 minutesauthorVishal Ribdiya
post

Here is part one of How to Keep Your Customers Happy & Increase Repeat Project

9. Know your products and services

Customers want to work with knowledgeable employees. Learn all you can about your products so you can be better equipped to answer customer questions. If you are unsure about something, ask for help.

10. Treat your customers individually

Not all customers are the same. Every customer has individual needs and concerns and they want to be treated with a personal touch that doesn’t make them feel like a number. Communicate the way your customers want to communicate.

11. Make it easy for your customers to complain

Your customers seem to have heard, especially when they are frustrated with the service they have received. Customers know what they like and at least about your service. Ongoing surveys are a reliable and consistent approach to getting feedback but don’t miss the opportunity when you’re with a customer. Just asking you sends a beautiful message about how you value your customers and their feedback.

12. Thank your customers for every opportunity you get

Thank you very much for your customers. Thank you for calling, bringing payment, meeting you at their home, calling for help, and yes, calling for a complaint! For many, there are options available and they chose your company over the competition.

13. Never accept your customers

Your customers are your business!

14. To be active

Don't wait for your client to reach you. Reach out to them in more than one way. Improving the first call resolution cases of the customer problem will improve the overall customer experience. Create a complete self-help interface, in which customers can solve their problems manually.

15. I will take responsibility

Tell your customer that you understand that you have a responsibility to ensure a satisfactory outcome of the transaction. Assure the customer that you know what she expects and will deliver the product or service at the agreed price. There will be no unexpected charges or costs to solve the problem.

August 03, 20202 minutesauthorAnkit Kalathiya