Laravel Basics

Laravelopen in new window is a web application framework that provides a "structure and starting point for creating your application, allowing you to focus on creating something amazing while we sweat the details." Laravel includes powerful features and built-in resources, which help boost your web application to the next level.

Why Laravel?

Laravel is an excellent choice for building a modern, full-stack web application. It is a progressive framework that will grow with you whether you are a beginner or a seasoned veteran. It is also highly scalable and is backed by a vast community. These are the reasons why Laravel is one of the most popular back-end frameworks available today.

How is Laravel made?

Laravel is a PHP framework that utilizes Object-Oriented PHP. Laravel also follows the Model-View-Controller (MVC) architecture, a design paradigm widely used by many web development frameworks.

When a web application is build using MVC will divide the application into three distinct parts, each with its task. The Model is the data of the application usually represented by a database. The View is the user interface and displays data from the model and received input from the user. Lastly, the Controller is the bridge between the Model and View. The Controller will request the data from the Model, process the data and then send it off to the View. The Model and View will never communicate directly as all communication will happen through the Controller. Now, some frameworks, like Laravel, will also include a Router. A router will receive a request from a user and determine which controller should handle that request. The main advantage of using MVC is that each part is not directly tied to any other. This loose coupling allows for any part of the web application to be replaced quickly and easily.

This video was created by codeSTACKr

What are the Laravel Requirements?

Because Laravel is a back-end PHP framework, it does require a local development environment. There are various options for developing and running a Laravel project on a local machine, depending on your operating system. Laravel does have some specific server requirements:

  • PHP >= 7.3
  • BCMath PHP Extension
  • Ctype PHP Extension
  • Fileinfo PHP Extension
  • JSON PHP Extension
  • Mbstring PHP Extension
  • OpenSSL PHP Extension
  • PDO PHP Extension
  • Tokenizer PHP Extension
  • XML PHP Extension

Warning

At the time of the writing, it is discouraged to use PHP 8. Configuration issues have occurred. Until a solution is found, it is best to use PHP 7.4.*

For Windows

For this class, the preferred local development environment is Laragon. It is stand-alone software explicitly designed for Laravel. Laragon includes many of the dependencies for a Laravel project, including git, composer and node. Laragon will also create friendly *.test domains for each project.

If you are unable to use Laragon, you may use Xamppopen in new window. Please talk to your instructor about further instructions.

For macOS

For this class, the preferred local development environment is Valet. It is a command-line application designed by the creators of Laravel. Valet automatically configures your Mac to always run in the background when you log in. It also includes a DNS that will create friendly *.test domains for each project.

If you are unable to use Laragon, you may use Mampopen in new window. Please talk to your instructor about further instructions.

For Linux

Please talk to your instructor about further instructions.

Installing Laravel

Once the local development environment has been set up and configured, it is time to create a new Laravel project. There are two common ways to create a new Laravel project: composer and the Laravel installer.

Installation Via Composer

With Composer installed, a new Laravel project can be created into a new folder using the following command in the terminal:

composer create-project laravel/laravel laravel-project

This command will create a new directory called laravel-project with Laravel inside. After finishing, the Laravel development server can be started using the Artisan CLIopen in new window.

cd laravel-project
php artisan serve

The Laravel Installer

The Laravel Installer can also be used to install Laravel. It can be installed global using Composer:

composer global require laravel/installer

Once the Laravel Installer has been installed, a new Laravel project can be created using the following command:

laravel new laravel-project

This will create a new directory called laravel-project with Laravel inside. After the application has been created, the Laravel development server can be started using the Artisan CLIopen in new window.

cd laravel-project
php artisan serve

Alternative Way

In this class, you will not be required to create a Laravel project from scratch. Instead, you will be provided Laravel with the starter files. After you have cloned the project's starter files, you will find Laravel already installed. But you will need to take some steps to make it fully functional.

From the cloned directory containing Laravel, enter the following commands into the terminal:

# Install dependencies
composer install

# Enstablish environment file
mv .env.example .env

# Generate key
php artisan key:generate

From there, you should be able to view the Laravel project using the friendly URL created by your local development environment.