DEV Community

Brian
Brian

Posted on

Getting started with Laravel

How to create a Laravel Project
For beginners who would like to get started with Laravel, i'll provide the most crucial snippets of code that you will encounter in this amazing framework

Prerequisites

  1. PHP: Laravel requires PHP 8.0 or later.

  2. Composer: This is a dependency manager for PHP

  3. Web server: Apache, Nginx, or Laravel's built-in-server

Start your XAMPP web server since this will be required for the database

Creatae a new project using composer directly. Replace project-name with the desired name

composer create-project --prefer-dist laravel/laravel project-name


Enter fullscreen mode Exit fullscreen mode

cd project-name

cd project-name
Enter fullscreen mode Exit fullscreen mode

Serve the Application

php artisan serve
Enter fullscreen mode Exit fullscreen mode

This command will start the development server at 'http://localhost:8000'.

Configure your environemnt

Laravel uses a '.env file for environmental configuaration. Open the '.env' file in the root of your project and configure your database and other settings

As for the latest installation it comes with sqlite by default but i prefer using mysql so we are going to change that

This is what it looks like by default

DB_CONNECTION=sqlite
# DB_HOST=127.0.0.1
# DB_PORT=3306
# DB_DATABASE=laravel
# DB_USERNAME=root
# DB_PASSWORD=
Enter fullscreen mode Exit fullscreen mode

change it to, make sure to uncomment the commented parts

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel-dev-database
DB_USERNAME=root
DB_PASSWORD=


Enter fullscreen mode Exit fullscreen mode

Run migrations
Laravel uses migrations to create database tables. Run the migration with

php artisan migrate
Enter fullscreen mode Exit fullscreen mode

Laravel uses MVC (Model, View, Controller) Architecture
We are going to discuss this in a moment

Congratulations, you have successfully created your first Laravel application.

Top comments (0)