Monday, 23 October 2017

How to change Laravel database configuration

Step 1: Locate the .env File

Laravel uses environment files (.env) to manage configuration settings, making it easy to switch environments without altering code. The .env file is where you'll define your database connection details. Navigate to the root directory of your Laravel project and find the .env file.

Step 2: Edit Database Configuration Settings

Open the .env file in your preferred text editor. You will see several database configuration options, including:


DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laradb
DB_USERNAME=root
DB_PASSWORD=root

Here is a screenshot with database setting.

Step 3: Clear Configuration Cache

After making changes to your .env file, it's essential to clear your application's configuration cache to apply the changes. Run the following command in your terminal:


php artisan config:clear

This command ensures that Laravel loads the new database configuration settings.

Step 4: Test the New Database Connection

To test our database setting we need to run the following command.


php artisan migrate


In case of any error always make sure to add exact database details in .env file

Step-by-Step Guide to Installing Laravel for Beginners

Step-by-Step Guide to Installing Laravel for Beginners

We can install Laravel very easily with multiple ways
So, before Laravel installation, please make sure that you have installed Composer on your machine.

There are different ways to install Laravel framework. Few of them are as follow
  1. Install Laravel via Composer Installer
  2. Install Laravel via Composer Create-Project command
  3. Downloading Laravel framework repo from github

1) Install Laravel via Composer Installer

We can download and install laravel via composer installer.

composer global require "laravel/installer"

Running the command composer global require "laravel/installer" will install the Laravel installer 
globally on your system. This allows you to create new Laravel projects from anywhere on your 
system by using the laravel new command.

2) Install Laravel via Composer Create-Project command


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

Download different older or new versions

composer create-project laravel/laravel blog  "5.1.*"
composer create-project laravel/laravel blog  "5.2.*"

Replace blog with your desire project name. These commands downloads Laravel and its dependencies, creating a new project directory for you

3) Downloading Laravel framework repo from github

On github Laravel framework repo is also avaible.Github allow us to download Laravel framework repo in zip format.as you can see in the below screenshot.

Offical Github laravel repo link:  https://github.com/laravel/laravel



In above screenshot you can see the downloading zip button from where we can click and download
their laravel zip installation. Unzip after download the repo and execute the following command to 
install decencies 

compose install


Running laravel framework

After successfully installing lravel framework on your system or server, next step is to run
the laravel.To run the laravel framework we need to execute the following command in larave
directory.

php artisan serve



Laravel csrf token mismatch for ajax post request

Error "CSRF Token Mismatch" commonly occurs if tokens do not match in both sessions and sent , and received requests.CSRF token he...