Install Laravel

How to create a Database in MYSQL?

Do you want to learn “How to create a database in MYSQL”? Read this step by step guide.

There are some steps that help to 

How to Create a Database in MYSQL: A Step-by-Step Guide

How to Create a Database in MySQL: A Step-by-Step Guide

Step 1: How to create a database in Mysql . So, we will start Apache and MySQL servers from XAMPP Control Panel.

Step 2: Open any web browser, like Chrome, and type localhost/phpmyadmin in URL.

Step 3: Now, click on the Databases tab and there, write the database named as sample and click on create.

Step 4: Now, you will have to find a file named .env, where you will have to specify the details for the MySQL server, like database name, username, etc. In that file, you will have to search for names starting with DB_.

Step 5: In that, you will find the DB_CONNECTION=mysql line. Below this are all the details specified for the database connection. You will have to specify the database name sample, that we created, after DB_DATABASE= and also specify username and password according to your need. Then save the file.

Step 6: Now, we will create a View in resources/views directory with the name demo.blade.php. Write the below code in the file.

<!DOCTYPE html>

<html>

<head>

<title>Demo Sample</title>

<style>

div {

font-size: 22px;

}

</style>

</head>

<body>

<div>

<?php

if(DB::connection()->getPdo())

{

echo β€œSuccessfully connected to the database => β€œ

.DB::connection()->getDatabaseName();

}

?>

</div>

</body>

</html>

Step 7: Write the following route in the β€˜web.php’ file in β€˜routes’ directory.

Route::get(β€˜blade’, function () {

    return view(β€˜demo’);

});

Step 8: Now, run the following Laravel artisan command to start the server:
php artisan serve

Step 9:Β And now, open the provided URL by the artisan in the browser withΒ /bladeΒ at the end.
http://127.0.0.1:8000/blade

EMAIL CONFIGURATION IN LARAVEL 

In this tutorial we learn about how to send email in Laravel dynamically. Mostly, we do a static email configuration in any programming/scripting language. The static configuration will work only for one user. So, what if you want to do an email setup for multiple users. In other words, if you are creating a kind of a portal or CRM in which you require to allow users to set their email configuration. So, is it possible to configure an email setting for every individual user? Yes, it is. In that case, you can store the configuration values in the database. Then, as per the current user, it can be accessed from the database and set the configuration. When we will do the dynamic email configuration with values from how to create a database in mysql, we will be overriding the email configuration by providing the necessary details through the database.

As we know, in Laravel, we configure the email settings in the .env file. It has linked with the mail.php file available in the config directory. Today, in this post, I will be showing you the step by step guide for overriding the default email configuration and make it dynamic. So, let’s go by creating a new project for this post.

After installing the laravel, there is a .env file inside your project folder.
Open the .env file

Database Configuration

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead <--- change database β€œhomestead” into your database name
DB_USERNAME=homestead <--- change username β€œhomestead” into your MySQL username
DB_PASSWORD=homestead <--- change password β€œhomestead” into your MySQL password

Mail Configuration

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io <--- change the host name
MAIL_PORT=2525             <--- change the port number according to host
MAIL_USERNAME=null         <--- change default username β€œnull” into your mail username
MAIL_PASSWORD=null         <--- change default password β€œnull” into your mail password
MAIL_ENCRYPTION=null       <--- change β€œnull” into the tls (TLS)

Note:
For MAIL_HOST,
β€œsmtp.gmail.com” for gmail host
β€œmail.domain.com” for domain host (If you buy the server)

If you want to use the gmail server for mail configuration:

Login to your gmail account and under My account > Sign In And Security > Sign In to google, enable two step verification, then you can generate app password, and you can use that app password in .env file.

MAIL_DRIVER= smtp
MAIL_HOST= smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME= test@gmail.com
MAIL_PASSWORD= gmailpassword
MAIL_ENCRYPTION=tls

After you make changes in your .env file, Run the command for removing the configuration cache => php artisan config:cache

I hope you understand and like this post. If you have any doubt regarding this post or other content regarding my site http://developerhelps.com/ .Please contact us.

Leave a comment

Your email address will not be published. Required fields are marked *