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
PHP: Laravel requires PHP 8.0 or later.
Composer: This is a dependency manager for PHP
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
cd project-name
cd project-name
Serve the Application
php artisan serve
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=
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=
Run migrations
Laravel uses migrations to create database tables. Run the migration with
php artisan migrate
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)