In this video we are going to learn about database setup in laravel 8.
First of all I'm just going to make the configuration.
For that you have to check out the two files.
Lets switch to the project goto the config folder.
You have to check that database.php file and here you will find that there is a lots of configuration is here.
Lets see the mysql configuration.
Here is a array of MySQL and here you can see that.
Configuration is coming from some env function.
We don't have to put the database name directly so lets see the .env file.
Inisde the project root directory.
You can see the .env file.
Just open this .env file and here just enter the database name ,user and password.
So first of all lets create a database.
For that goto the browser and.
Open http://localhost/phpmyadmin.
Now click on database.
Here type database name.
Let say database name is laravel8prodb.
Now switch to the project and here database name laravelprodb,
username which is root.
and password which is blank.
So leave password blank.
Now save the .env file.
So the configuration is ready now.
After making changes in .env file, you must have to restart your application.
So for that just switch to the command prompt.
and here press ctrl+c for stop the process then type here command.

php artisan serve

Now lets create a controller and inside the command prompt run the command.

php artisan make:controller PostController

Now switch to the project and just open PostController.
Now inside the PostController crate a function which fetch all post from the database.
Before the creating this function lets create a table inside the database.
So switch to phpmyadmin and inside the laravelprodb.
Crate a table lets say table name is posts.
Number of column 3 now click on go.
Now enter the column name id which is integer and their length let say 10 and set autoincremet true.
Now enter another column name title and type varchar length 200.
and last column name is body and type text.
Now click on save.
Alright the table is created.
Now lets create some post.
Click on insert and type type lets say \"post first title\" and here inside the body put the value \"this is first post description\".
Ok in this way create on more post.
Now switch to the project and inside the PostController.
Create method for fetch the post from the database.
Here I am going to use DB to perform database operations.
Laravel's database query builder provides a convenient,
Fluent interface to creating and running database queries.
It can be used to perform most database operations in your application and works on all supported database systems.
First of all import DB on top of the page.

use Illuminate\\Support\\Facades\\DB;

Now create a function and fetch all posts from database.

public function getAllPost()
$results = DB::table('posts')->get();
return view('posts',['posts'=>$results]);

Now lets create the posts view.
So go to the resource folder and right click on views and crate a new file.
And file name is posts.blade.php.
Now open this file.
Inside the view show here all the post so write the following code.

@foreach($post in $posts){

Alright now create the routes for this.
So goto the web.php and here just type.


Now save the file.
Lets check this.
So for that.
Switch to the browser and go to the url localhost:8000/posts.
You can see here the posts with their title and and description.
So in this way you can configuration a database inside you laravel 8.