May 30, 2024 5 minute read
Starting a new Laravel Project
Table of Contents
What is Laravel?
Laravel is a popular open-source PHP framework designed for web application development. It follows the Model-View-Controller (MVC) architectural pattern and provides a robust set of tools and resources for building modern, maintainable, and scalable web applications. For more details, check out this blog post.
Getting started with Laravel
PHP & Composer
Before creating your first Laravel Project, make sure your local machine, has PHP and Composer installed. If you are developing on macOS or Windows, PHP and Composer can be installed in minutes via Laravel Herd.
Herd
Inside Herd, you can set the path you want to use for your projects, so that Herd has access to all sub-folders within the listed directories.
Starting a Project
Open the terminal and move into the directory you have specified in Herd. My directory is called "Projects":
cd Projects/
Now the configuration of your new Project starts. You can choose the name of your project or also leave out this step, then Laravel will ask you for the name of your project:
laravel new [project_name]
Or:
laravel new
Starter Kits
After this, you can choose to install a starter kit with your new project. You can either use no starter kit at all or choose between Laravel Breeze and Laravel Jetstream.
Quick Intro
Laravel starter kits are pre-packaged sets of tools, configurations, and templates designed to help developers quickly start new projects, allowing them to focus more on the unique aspects of their application rather than setting up the basic infrastructure.
Laravel Breeze
Provides a simple and minimal starting point with authentication features.
Features:
- Basic authentication (login, registration, password reset, email verification)
- Uses Tailwind CSS for styling
- Ideal for small projects or as a learning tool for new Laravel developers
Laravel Jetstream
Offers a more robust starting point for applications requiring advanced features.
Features:
- Authentication and session management
- Two-factor authentication
- API support via Laravel Sanctum
- Teams and user profile management
- Uses Tailwind CSS and either Livewire or Inertia.js for the frontend
For my first project, I will go on with no starter kits.
Testing Framework
The next choice, you have to make, is which testing framework you want to use. Your two options in terminal are Pest and PHPUnit, though there are other testing frameworks you could use.
PHPUnit
PHPUnit is the standard testing framework for PHP, and it comes pre-configured with Laravel. It's used for unit testing, feature testing and integration testing.
Pest
Pest is a PHP testing framework with a focus on simplicity and an elegant syntax. It provides a more readable and streamlined syntax compared to PHPUnit, making it easier for developers to write tests. Pest is compatible with PHPUnit, so you can use both frameworks together.
For this project, I will go with Pest.
Git Init
After you've chosen your Testing Framework, you can choose to initialize a Git repository within your project.
For more information about what Git is, check out this blog post.
After this, the terminal will start creating your project, up until it has to do migrations for the database.
Database
At this step, you get to choose between five different database applications.
Here is an overview over those five databases and what they can be used for:
- SQLite: is a lightweight, file-based database. It's easy to set up and ideal for small projects, testing or development.
- MySQL: is popular for relational databases. It is commonly used in Laravel projects.
- MariaDB: is also popular for relational databases, though it is more scalable and offers a higher query speed when compared to MySQL. This makes it good for managing large-sized data.
- PostgreSQL: is an advanced open-source relational database. It's suitable for projects requiring complex queries.
- SQL Server: is Microsoft's relational database and is good for enterprise applications.
Unless you are using SQLite, there will be further steps to follow. I will be using MySQL for this project. It will update the default database and ask if you want to run the default database migrations.
You can choose to run them at this step or do it later, when you have your database connected. I choose to run them manually later.
Then the terminal will run the commands to set up your project, and you will have a new folder in your directory.
That's it! You've set up your first Laravel project.