Courses

[FREE] Laravel 11 For Beginners: Your First Project

Install Laravel: Composer or Laravel Installer

In this first lesson, we will create a new project with Laravel. The official Laravel documentation installation page has a lot of information. There is more than one way to install Laravel.

The official Laravel documentation is mainly based on a tool called Laravel Sail, which is based on Docker. But we won't be using Sail in this course. To use it, you must know at least the basics of Docker. And we don't want unnecessary prerequisites for beginners, right?

My personal preference is to use Laravel installer.

But before we use the installer, we need to prepare your machine.


Preparing Your Computer: Composer and Web-Server

To install Laravel, you must first install composer on your machine. Composer is later used to install every Laravel package.

Next, you need to have a PHP web server on your machine. There are different "bundle" tools for different operating systems that include Nginx/Apache, PHP, MySQL, and a few more things for PHP web-projects:

  • Laravel Herd (MacOS)
  • Laravel Valet (MacOS/Linux)
  • Laragon/XAMPP (Windows)
  • etc.

On my machine, I will be using Laravel Valet as this is my preferred way.

Notice: Laravel 11 requires at least PHP 8.2 version.


Install and Launch Laravel

First, we need to install the Laravel Installer globally.

composer global require laravel/installer

Then, we can use the command laravel new example-app to create a new Laravel project: the folder example-app will be created automatically with the Laravel files inside.

Let's create a new project.

laravel new project

This command will create a new Laravel project inside a project folder.

Because I am using Laravel Valet, it will automatically generate a domain project.test, which I can immediately launch in the browser.

When the installer is executed, there are a few options to choose from:

  • Starter kit: For now, don't choose any starter kit like Breeze or Jetstream. We will talk about them later in this course.
  • Testing framework: For now, for this course, the testing framework (PHPUnit or Pest) doesn't matter. We will talk about testing in separate other courses.
  • DB Engine: Choose SQLite, MySQL, or other DB engine depending on which you want to work with.

Laravel uses SQLite as a default SQL database engine. After the Laravel project is created, the SQLite database is created automatically in the database folder, with the DB structure built from the Migration files (we will talk about migrations later).

Now, when we visit http://project.test in the browser, we can see the default Laravel welcome page.

If you open the project in the code editor and specifically the routes/web.php file, you will see one Route is defined.

routes/web.php:

use Illuminate\Support\Facades\Route;
 
Route::get('/', function () {
return view('welcome');
});

Here we have a / homepage, which leads to a View called welcome. Views are found in the resources/views folder.

So that's it, we installed Laravel!

In the next lesson, let's talk about how to create pages: how the routing and the views work.

avatar

Hello, Thank you so much foe your knowledge sharing. Your cources are really usefull. I would like to ask you to make more video cources. We have laravel documentation and a lot of written information in internet. I think your cources uniquqe, among other reasons, because of the way you explain information by voice. Thank you

avatar

Hello, thank you for the kind words. Unfortunately, video courses are a bit harder to make and they get outdated very quickly. We are currently switching to more text based courses with a goal to update them as soon as possible

avatar

I'm happy with text based courses, I find them much better to learn with than video's, I constantly have to pause and rewind videos, whereas I can just go at my own pace with written ones, so keep it up :)

avatar

For me text is better than video.

avatar

Thanks for this

avatar

im getting PRAGMA foreign_keys = ON;

avatar

Will there be more information about laravel with docker?

avatar

No plans, there are many information about docker already free and