What is Laravel?

Laravel is a free, open-source PHP web framework used for web application development. It was created by Taylor Otwell in 2011 and has since become one of the most popular PHP frameworks.

Laravel is designed to make it easier for developers to write web applications by providing a set of tools and features that simplify common web development tasks. Some of the key features of Laravel include:

  • MVC (Model-View-Controller) architecture: Laravel follows the MVC architectural pattern, which separates the application logic, presentation, and data storage layers. This makes it easier to develop and maintain large applications.
  • Database migrations: Laravel provides a set of tools for managing database schema changes, including creating and modifying tables and columns.
  • Object-relational mapping (ORM): Laravel includes an ORM called Eloquent, which makes it easier to work with relational databases by providing a simple, ActiveRecord-like interface.
  • Blade template engine: Laravel uses the Blade template engine to make it easier to create and maintain dynamic, data-driven views.
  • Artisan command-line interface: Laravel includes a command-line interface called Artisan, which provides a number of helpful commands for managing and developing your application.

Laravel is known for its simplicity and elegant syntax, making it a popular choice for developers building web applications.

PHP variables

Variable is an image or name that represents a worth. Factors are utilized for putting away qualities, for example, numeric qualities, characters, character strings, or memory addresses with the goal that they can be utilized in any piece of the program.

How to declare variable in PHP (Naming convention of variable in PHP)

  1. Variables start with the $ sign followed by the name of the variables
  2. A variable name must start with a letter or the underscore character
  3. A variable name cannot start with a number
  4. A valuable name can only contain alpha numeric characters and underscores (A-z and _)
  5. Variable name are case sensitive ($age and $AGE are two different types of variables)
<?php
$txt = “Hello world!”;
$x = 2;
$y = 7;
?>

After the declaration of the statement above, the variable $txt will hold the value Hello world!, the variable $x will hold the value 2 and the variable $y will hold the value 7

User defined function in PHP

User defined function in php is quite a common thing. You can create User defined functions in PHP. User defined function is very useful feature in the programming language. User defined function allows you to create your own functions and use them anywhere in your application without worrying about the names of the functions. You can also specify parameters for these User defined functions and even return values as well as null values.

function functionName() {
  code to be executed;
}

For loop PHP

The FOR loop is a special construct that allows you to repeat blocks of code a certain number of times, without having to write out the whole thing each time. This is useful for iterating over collections, such as arrays, in order to perform some action.

It can be used when we know the how many times code will be repeated. FOR loops are executed from left to right (as opposed to WHILE loops which are executed from top to bottom). They also use an incrementing variable instead of a counter variable (which makes them more like a while loop than a while loop).

Syntax

for (initial number; condition; increment number) {
  statement to be executed;
}

PHP do while Loop

The do while loop in PHP is a statement that executes a block of code while a certain condition is true. This can be used to implement an infinite loop, or to repeat a block of code zero or more times. The syntax for the do while loop looks like this:

do {
// code you want to execute
} while (condition);

It will first execute the code block and then check for the condition.

How to add comments in PHP?

A PHP comment is a line of code that is not run as part of the program. It’s sole function is to be readable by someone who is scanning the code. 

Comments may be employed for

  1.  Making your code clear to others.
  2. Remind yourself of what you accomplished, Most programmers have encountered the challenge of having to rediscover what they accomplished when returning to their own work after a year or two. 
  3. Comments might serve as a reminder of your thoughts when writing the code.

Example for adding comments in PHP code.

  1. Syntax for single line comment:
<!DOCTYPE html>
<html>
<body>

<?php
// This is a single-line comment

# This is also a single-line comment
?>

</body>
</html>

2. Syntax for multiple line comment:

<!DOCTYPE html>
<html>
<body>

<?php
/*
This is a multiple-lines comment block
that spans over multiple
lines
*/
?>

</body>
</html>

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>