How to configure username and email in git?

There are 2 way to configure username and email in git.

  1. Globally
  2. Local (Repository basis)

Set Username and email globally.

$ git config --global user.name "PHP Spider"
$ git config --global user.email phpspiderblog@example.com

Set username and email locally.

Switch to the repository for which you want to configure.

$ git config user.name "PHP Spider"
$ git config user.email phpspiderblog@example.com

How to rename a git local and remote branch?

As we are working in a team and using git. Many developers are working on the same project in this git is very helpful. So when we have to rename the git branch? You created a branch and pushed on the remote server, after pushing you got to know that branch name is incorrect. To rename the branch you can use following steps.

Step 1. If you are in branch A and want to rename branch B

git branch -m <oldname> <newname>

If you want to rename the current branch

git branch -m <newname>

How to Manually Logging In A User in Laravel

If you want to log an existing user into your laravel application, There are various methods available we will discuss them one by one. To login the user manually in Laravel you need to follow the simple steps below for login.

Step 1. Fetch the user from the DB which you want to logging In in the Laravel.

$user = User::find(1); //You can add as per your condition (with email,password etc.)
Auth::login($user);

It will allow the user to logging in the Laravel application.

To manually login the user in Laravel has second optional argument, which is used for remember me. If you pass the second argument as true. If this argument passed as true then user will be logged in for indefinite time.

Auth::login($user, true);

https://laravel.com/docs/8.x/authentication#authenticate-a-user-instance

What is the difference between = , == and === ?

All of the above are called operators. Operator is a string which instructs PHP to perform given action.

= is called assignment operator. It is used for assign value to a variable. It will assign value left to the variable.

$x = 5; //5 is assigned to variable x.
$name = "Test string"; // Test string assigned to variable name.

== is called comparison operator. Double equal (==) is used to compare operands on both sides (left and right side). Double equal will ignore the type of operands.

$x = 5;
$y = "5"
$x==$y; //It will give true

=== is also called comparison operator, But it will check the type of the variable along with value.

$x = 5;
$y = "5";
$x === $y; //It will give false. Because types of $x and $y are not same.

I hope it clears. If you need any help add in the comment.

How to add empty directory to git repository?

Whenever we are creating a directory in git folder git shows us nothing to commit, it is by the design of git we can not commit empty directories. So to commit empty directory to git repository follow the steps below

  1. Create an empty directory
$ mkdir test

2. Then create an empty directory

$ touch test/.gitkeep

3. Add your directory with this command

$ git add test

4. Now you can commit your empty directory to git repository.

$ git commit -m "Empty directory added to git repository"

How to log query in laravel

To log a query in laravel there are multiple methods available. I am going to share one of the method log query in laravel.

Why we have required to log queries? Sometimes we are not getting correct results when we are running our application. Sometime not able to figure out issue. We have requirement to check the query what is running in the backend. So we need query which can be get by logging in laravel. To log query in laravel follow the below steps.

  1. Open the AppServiceProvider.php file you can found app/Providers/AppServiceProvider.php on the path.
  2. Add the following code to log query in laravel
        \DB::listen(function($sql) {
            \Log::info('SQL', [$sql->sql]);
            \Log::info('Query parameters', [$sql->bindings]);
            \Log::info('Query execution time', [$sql->time]);
        });

The above code will log queries executed on the page, their parameters and the execution time as well in the log file. All the queries in the laravel logged by above code in the log file. You can add condition as per your choice or requirement. If you want to log only specific query you can add this code to your desired place to log the query.

For more information to log query in laravel you can refer to https://laravel.com/docs/8.x/database#listening-for-query-events

One other option I would like to recommend to use telescope. https://laravel.com/docs/8.x/telescope#introduction

How to check php version in command line?

If you want to know the PHP version you are running through the command line, you need to just type in the command the following line.

php -v

It will give you the current php version of your system which is currently using and output of PHP version like this (not exactly, depends on your version)

PHP 7.4.3 (cli) (built: Oct  6 2020 15:47:56) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.3, Copyright (c), by Zend Technologies