Laravel Tutorial Series
Published: 2021-10-18 09:32:33

## What is Laravel?

Laravel is a PHP based web application framework with expressive, elegant syntax. A web framework provides a structure and starting point for creating your application. 

Laravel strives to provide an amazing developer experience while providing **powerful features such as thorough dependency injection, an expressive database abstraction layer, queues and scheduled jobs, unit and integration testing, and more.**

Before delving deeper into the framework, its important to understand the Laravel ecosystem and what it can do for you.

### The Laravel Ecosystem

**Laravel Vapor** is a serverless deployment platform for Laravel, powered by AWS. It provides On-demand auto-scaling with zero server maintenance.
**Laravel Horizon** provides a beautiful dashboard and code-driven configuration for Laravel powered Redis queues. Horizon allows you to easily monitor key metrics of your queue system such as job throughput, runtime, and job failures.
**Laravel Lumen** is the perfect solution for building Laravel based micro-services and blazing fast APIs. In fact, it's one of the fastest micro-frameworks available..
**Laravel Valet** is a Laravel development environment for macOS minimalists.
**Laravel Dusk** provides an expressive, easy-to-use browser automation and testing API.
**Laravel Socialite** Laravel provides a simple, convenient way to authenticate with OAuth providers using Laravel Socialite. Socialite currently supports authentication with Facebook, Twitter, LinkedIn, Google, GitHub, GitLab, and Bitbucket.
**Laravel Forge**  is a server management feature.To learn more visit [Link](https://forge.laravel.com/)
**Laravel Nova** is a beautifully designed administration panel for Laravel. 
**Laravel Sail** is a light-weight command-line interface for interacting with Laravel's default Docker development environment. Sail provides a great starting point for building a Laravel application using PHP, MySQL, and Redis without requiring prior Docker experience.
**Laravel Mix** provides a fluent API for defining webpack build steps for your Laravel application using several common CSS and JavaScript pre-processors.
**Laravel Sanctum** provides a featherweight authentication system for SPAs (single page applications), mobile applications, and simple, token based APIs.
**Laravel Telescope** makes a wonderful companion to your local Laravel development environment. Telescope provides insight into the requests coming into your application, exceptions, log entries, database queries, queued jobs, mail, notifications, cache operations, scheduled tasks, variable dumps, and more.
**Laravel Envoyer** You can deploy at any time of day or night with confidence that your users will never experience downtime.
**Laravel Echo** used to implement realtime, live-updating user interfaces.
**Laravel Spark** is the complete recurring billing solution for Laravel. A starter-kit for your next great SaaS application.
**Laravel Cashier** provides an expressive, fluent interface to Stripe's subscription billing services. It handles almost all of the boilerplate subscription billing code you are dreading writing. In addition to basic subscription management, Cashier can handle coupons, swapping subscription, subscription "quantities", cancellation grace periods, and even generate invoice PDFs.
**Laravel Scout** provides a simple, driver based solution for adding full-text search to your Eloquent models. Using model observers, Scout will automatically keep your search indexes in sync with your Eloquent records.
**Laravel Jetstream** is a beautifully designed application starter kit for Laravel and provides the perfect starting point for your next Laravel application. Jetstream provides the implementation for your application's login, registration, email verification, two-factor authentication, session management, API via Laravel Sanctum, and optional team management features.

### Getting Started

There are a variety of options for developing and running a Laravel project on your own computer. While you may wish to explore these options at a later time, Laravel provides Sail, a built-in solution for running your Laravel project using Docker.

Docker is a tool for running applications and services in small, light-weight "containers" which do not interfere with your local computer's installed software or configuration. This means you don't have to worry about configuring or setting up complicated development tools such as web servers and databases on your personal computer. To get started, you only need to install [Docker Desktop](https://www.docker.com/products/docker-desktop).

####On MacoS

If you're developing on a Mac and Docker Desktop is already installed, you can use a simple terminal command to create a new Laravel project. For example, to create a new Laravel application in a directory named "example-app", you may run the following command in your terminal:

```
curl -s "https://laravel.build/example-app" | bash
```
Of course, you can change "example-app" in this URL to anything you like. The Laravel application's directory will be created within the directory you execute the command from.

After the project has been created, you can navigate to the application directory and start Laravel Sail. Laravel Sail provides a simple command-line interface for interacting with Laravel's default Docker configuration:

```
cd example-app

./vendor/bin/sail up
```
The first time you run the Sail up command, Sail's application containers will be built on your machine. This could take several minutes. Don't worry, subsequent attempts to start Sail will be much faster.

Once the application's Docker containers have been started, you can access the application in your web browser at: http://localhost.

#### On Windows

Before we create a new Laravel application on your Windows machine, make sure to install Docker Desktop. Next, you should ensure that Windows Subsystem for Linux 2 (WSL2) is installed and enabled. WSL allows you to run Linux binary executables natively on Windows 10. Information on how to install and enable WSL2 can be found within Microsoft's developer environment documentation.

After installing and enabling WSL2, you should ensure that Docker Desktop is configured to use the WSL2 backend.

Next, you are ready to create your first Laravel project. Launch Windows Terminal and begin a new terminal session for your WSL2 Linux operating system. Next, you can use a simple terminal command to create a new Laravel project. For example, to create a new Laravel application in a directory named "example-app", you may run the following command in your terminal:
```
curl -s https://laravel.build/example-app | bash
```

Of course, you can change "example-app" in this URL to anything you like. The Laravel application's directory will be created within the directory you execute the command from.

After the project has been created, you can navigate to the application directory and start Laravel Sail. Laravel Sail provides a simple command-line interface for interacting with Laravel's default Docker configuration:
```
cd example-app

./vendor/bin/sail up
```
The first time you run the Sail up command, Sail's application containers will be built on your machine. This could take several minutes. Don't worry, subsequent attempts to start Sail will be much faster.

Once the application's Docker containers have been started, you can access the application in your web browser at: http://localhost.

#### On Linux

If you're developing on Linux and [Docker](https://www.docker.com/) is already installed, you can use a simple terminal command to create a new Laravel project. For example, to create a new Laravel application in a directory named "example-app", you may run the following command in your terminal:

```
curl -s https://laravel.build/example-app | bash
```
Of course, you can change "example-app" in this URL to anything you like. The Laravel application's directory will be created within the directory you execute the command from.

After the project has been created, you can navigate to the application directory and start Laravel Sail. Laravel Sail provides a simple command-line interface for interacting with Laravel's default Docker configuration:
```
cd example-app

./vendor/bin/sail up
```

The first time you run the Sail up command, Sail's application containers will be built on your machine. This could take several minutes. Don't worry, subsequent attempts to start Sail will be much faster.

Once the application's Docker containers have been started, you can access the application in your web browser at: http://localhost.

#### Choosing Your Sail Services

When creating a new Laravel application via Sail, you may use the with query string variable to choose which services should be configured in your new application's docker-compose.yml file. Available services include mysql, pgsql, mariadb, redis, memcached, meilisearch, minio, selenium, and mailhog:
```
curl -s "https://laravel.build/example-app?with=mysql,redis" | bash
```

If you do not specify which services you would like configured, a default stack of mysql, redis, meilisearch, mailhog, and selenium will be configured.

#### Installation Via Composer
If your computer already has PHP and Composer installed, you may create a new Laravel project by using Composer directly. After the application has been created, you may start Laravel's local development server using the Artisan CLI's serve command:

```
composer create-project laravel/laravel example-app

cd example-app

php artisan serve
```

##### The Laravel Installer

Or, you may install the Laravel Installer as a global Composer dependency:
```
composer global require laravel/installer

laravel new example-app

cd example-app

php artisan serve
```

Make sure to place Composer's system-wide vendor bin directory in your $PATH so the laravel executable can be located by your system. This directory exists in different locations based on your operating system; however, some common locations include:

**macOS:** $HOME/.composer/vendor/bin
**Windows:** %USERPROFILE%\AppData\Roaming\Composer\vendor\bin
**GNU / Linux Distributions:** $HOME/.config/composer/vendor/bin or $HOME/.composer/vendor/bin

For convenience, the Laravel installer can also create a Git repository for your new project. To indicate that you want a Git repository to be created, pass the --git flag when creating a new project:
```
laravel new example-app --git
```

This command will initialize a new Git repository for your project and automatically commit the base Laravel skeleton. The git flag assumes you have properly installed and configured Git. You can also use the --branch flag to set the initial branch name:
```
laravel new example-app --git --branch="main"
```

Instead of using the --git flag, you may also use the --github flag to create a Git repository and also create a corresponding private repository on GitHub:
```
laravel new example-app --github
```
The created repository will then be available at **https://github.com/<your-account>/example-app.** The github flag assumes you have properly installed the GitHub CLI and are authenticated with GitHub. Additionally, you should have git installed and properly configured. If needed, you can pass additional flags that supported by the GitHub CLI:
```
laravel new example-app --github="--public"
```
You may use the --organization flag to create the repository under a specific GitHub organization:
```
laravel new example-app --github="--public" --organization="laravel"
```

In the next tutorials we will be going through important concepts you need to understand before getting started with Laravel. This are :

**- Request Lifecycle**
**- Configuration**
**- Directory Structure**
**- Service Container**
**- Facades**