First steps to create applications in Laravel on Windows using Laragon

Video thumbnail
Video thumbnail

Today who has not heard of Laravel; which is an excellent and very popular framework, which is characterized by having a large community, recurring updates and all kinds of integration, packages and features that we can use very easily.

Laravel is a framework for PHP that is used to develop server-side web applications, but we can easily integrate it with other technologies such as Node, Vue, React, among others, since from a Laravel project, we also have access to Node.

Laravel offers a set of functions and tools that allow you to create a clean, structured and easy-to-maintain code, and best of all, it is scalable with the immense amount of features that the framework has.

A Laravel project is exquisitely segmented into modules ranging from database management, authentication, validation, routing, blade views, models, migrations, and many more.

One of the most fascinating features that Laravel has is its ORM called Eloquent with which we can make queries using the Query Builder or Eloquent itself.

Furthermore, Laravel has a large community of developers who regularly contribute packages and libraries to improve the platform. It is a very useful tool for developers looking to increase their productivity and build high-quality and professional web applications quickly and efficiently.

At this point I hope I have convinced you to work with Laravel.

Create a project in Laravel

In this post, we are going to create our first application in Laravel on Windows; before starting it is necessary that you have the necessary Laravel ecosystem that you can find more information here:

Install Laravel.

Remember that if you want to use Laragon on Windows but you don't know how to prepare everything so that it is ready, we have an entry in which we prepare our ecosystem to work with Laravel installed and our project created.

As you can see, it is a list of software to take into account, since we need a bit of everything to work comfortably with Laravel, which we are going to analyze in the next section.

Software necessary to create our apps in Laravel

You can install all these software manually and this is beyond the scope of this entry, or you can install a software known as Laragon, which provides us with all the necessary tools to start creating our applications in Laravel; best of all, if you already have some of the necessary software installed on your computer, such as composer, Node/NPM or a LAMP, this does not affect Laragon and vice versa; you can install Laragon with complete confidence that nothing on your PC will stop working.

A bit about Laragon, the chosen one to work with Laravel

Laragon in short is a necessary and fundamental software kit to create our apps in Laravel or any other PHP framework or even Node; It brings us already ready Node, NPM, Composer, Redis, the complete LAMP, a decent terminal and other additions but we already covered this before.

Creating our first application in Laravel

Video thumbnail

Laravel is always a bit more complicated if you compare it with other frameworks like CodeIgniter, when it comes to installing and using it; Laravel is a huge framework that has EVERYTHING and is extensible through packages created specifically for Laravel or simply PHP packages; as if this were not enough, it also has a perfect integration with Node, therefore we have a HUGE range of possibilities not only on the server side with Laravel, but also on the client side with Node that we can integrate Vue, Bootstrap, React, Angular and anything that can be installed via Node that we teach in my Laravel course:

Once we already have the necessary software, the next thing we have to do is create our app; to do this, the first thing you must do is activate your Laragon from the "Start all" button:

Laragon window
Laragon window

You open the console that brings us from the terminal button:

Terminal Laragon
Terminal Laragon

And here you are going to execute the command that we will see in the next section.

Install the Laravel 13 installer via composer with Laragon

We already have the entire ecosystem ready to develop our apps in Laravel 13; but before we start creating our project, we need to install the Laravel installer dependency (via composer) which will allow us to create a Laravel project via the command line.

$ composer global require laravel/installer

The above command allows you to install the Laravel installer as a PHP dependency via composer, which was one of the software required to work with Laravel.

Create the Laravel app via the above installer

Now with our installer ready, the next thing we are going to do is create our application in Laravel; we execute:

$ laravel new blog

Where blog is simply the name you give your Laravel project; you can put any name, without spaces, special characters, etc; try to keep it simple.

And with this we already have our project in Laravel in its latest version perfectly created.

General explanation of a Laravel project

As you can see, Laravel has a significant number of files and folders that together make up the framework and its structure; it uses a bit of everything from integration with NPM through Node to everything necessary for a framework from a PHP point of view; here we are going to explain the following structure a bit so that you know what each component does in general terms:

Proyect structure Laravel
Proyect structure Laravel
  • In the routes folder we can create our routes for our application, that is, the way in which we can access the functions defined within our controllers, we must specify a route to indicate which route will correspond to which controller and its function.
  • The resources folder stores web resources without compiling or generating them; that is, sass CSS files, or imports and definitions of Node modules (you will also see that we have a package.json to define Node dependencies), are defined here and by means of a command they are generated in the public folder in which we have our CSS and JS files ready to be consumed by our browser; also here you will find other resources such as images, videos, etc; our views are also in the resources folder.
  • We also have the config folder, in which we can make different configurations of our application; database, emails, etc; we have a file called .env which is ideal for development environments where we have global and general configurations of our project; the same configurations that we got in the previous folder we can define here to make a clear distinction between the development configurations (those stored in the .env file) and the production configurations (those that are defined in the multiple files within the config folder).
  • We have an Http folder where our controllers are located, and also another component that is the middleware that defines functions in which we can intercept and execute actions before the controller and another folder called Requests where validation files for the forms are generated.
  • The vendor folder stores the Laravel dependencies installed by composer, as well as any other dependencies installed by us.
  • In the node_mdoule folder, which you will only have if you run the npm install command, you will find all the node modules.

These are some of the most important components, but you can grab the full list at: Laravel: Directory Structure.

Know the current version of your Laravel and update

Video thumbnail

Laravel is the PHP framework by reference and for many reasons it has become the reference web framework and not only in PHP; Laravel follows a custom Model-View-Controller (MVC) architecture since, extending quite a bit to this architecture, Laravel has provides a simple and elegant syntax for developing web applications and a large number of functionalities to develop all kinds of applications.

If there is one thing that makes Laravel stand out, apart from its excellent framework full of various useful features and a most extensible all-terrain framework with both php packages and Node packages, it is because of its development team. that it is always incorporating new features and fixing bugs; and with this constant updates of the most popular php framework today; but this behavior can generate a couple of circumstances that we are going to address in this post:

  • Find out the current version of Laravel installed in your project
  • Update a project in Laravel

Find out the current version of Laravel installed in your project

We are going to learn how we can find out the current version of your project in Laravel: which is a fundamental task when we want to update an existing project to another version, find out if it is convenient for us to update and if this will have a negative impact on our disabled project on partially or totally or on the contrary, the project would be working in a perfect and stable way.

To find out what version of Laravel we are using, just run the artisan command

$ php artisan --version 

At this point, it is recommended that you see the releases on the official Laravel website, obtain information on all the updates that the Laravel team have made and see if any would negatively affect the project you already have created.

Update a project in Laravel

To update a Laravel project, it is recommended to follow the following steps:

  1. Create a backup of your current project in case something goes wrong during the update process and you can check if there are any issues with the stable version.
  2. Check the current version of Laravel you are using and compare it to the most recent version available; to do this, you can use the above command or check your composer.json and search for the Laravel package.
  3. Update composer dependencies by opening terminal in your project directory and running the composer update command. This will update all dependencies to their latest versions.
  4. Update configuration files whose changes are required for the newer version of Laravel; this is somewhat complicated, since many times you have to make additional changes at the project level.
  5. If you have customized your project views, make sure they are still compatible with the new version of Laravel; usually in views there are not many changes to make.
  6. Make sure that the rest of the components are supported by the new version of Laravel; in Laravel, at least the basic resources like controllers, models… are kept intact.
  7. Lastly, test your app and verify that everything works as expected.
  8. It is important to note that additional updates may sometimes be required depending on the specific nature of your project. Therefore, always refer to the official Laravel documentation and perform the necessary tests before deploying the new version to production.

As an additional recommendation, make a list and verify that it is easier, whether to update the project or create a new project and copy the dependencies.

Example of Laravel update to version 10

Now that we know what version of Laravel we have installed on our computer and whether or not we are going to have problems with our project, the next step that remains is to update; for that we have to go to the file called composer.json and look for the package called "laravel/framework": "^10.0" and depending on the version we want to update of Laravel we would have to place the exact version; for example, if we want to update to 1010:

"laravel/framework": "10.10",

Or if we want to update to the latest 10:

"laravel/framework": "^10.0",

We simply specify the "^" character. After you know which version of Laravel you are going to update to, the next thing we will do is execute the following command:

$ composer update

As you can see, it is a composer command and not a php artisan command, because it is composer that is in charge of updating and installing packages for our project, including our framework.

The command takes a while while it downloads and installs all packages including Laravel; Also remember that when we change versions, many times you have to make additional configurations at the project level.

Migrating a project from Laravel 11 to 12

Video thumbnail

I want to quickly tell you how you can update Laravel 11 to Laravel 12, as simple as I told you in the previous video where I was talking about the new features and so on, which is what is new and we have very little. This is basically what we have to do, simply place a 12:

composer.json

laravel/framework to ^12.0
phpunit/phpunit to ^11.0
pestphp/pest to ^3.0

If you have a minimum version of php unit or Pest you can also upload it and little else; we execute:

$ composer install

That's basically all here, remember that you may have problems with other third-party dependencies, that is, packages installed by you that are or are not part of the Laravel ecosystem that may have conflicts between versions and in that case you must decide whether to update Laravel or remove the package.

Artisan: The command line to create components in Laravel

At this point you already know the structure of a project in Laravel, we can start creating components; to create the different components that we explained in the previous section, we use the command line, through artisan, which is the one that is in charge of creating the different Laravel components; to see everything we can create, run:

php artisan

And you will see a very complete and organized list of everything we can do with Laravel, from creating controllers, models, migrations and many other things that we will discuss in another post; but stay with the idea that here we can perform different operations to create components in Laravel.

However, Laragon has been a paid product for some time now, and we have a new tool called Install Laravel Herd that we can use instead.

Conclusions

And up to here we leave this first entry on how to take the first steps with Laravel where we already installed the necessary tools and software to create the application in Laravel and we know the structure of a project and we introduce the command line known as artisan and of course, create and connect to our database in MySQL.

Remember that if you want more, I have multiple resources between books and courses to master Laravel.

If you were left wanting more, you can see other articles about Laravel, my course or book on Laravel or this playlist:

I agree to receive announcements of interest about this Blog.

We are going to take the first steps with Laravel, we are going to talk from its installation, the configuration of the ecosystem in Windows and generate our first project and explain the structure of Laravel directories and files.

| 👤 Andrés Cruz

🇪🇸 En español