In this video we are going to learn about Livewire With Database.
So lets see how can use database in livewire.
So first of all lets create a database
So just open phpmyadmin.
Just create here a new database.
Lets say database name is livewiredb.
Now switch to project and just open .env file and
Here just add the database name livewiredb User root and Password blank in my case.
Now lets create a component.
So go to the command prompt and type the command.

php artisan make:livewire Users

Now switch to the project
And lets create the route for User component.
So lets open the web.php file and create the route.


Now go to the database directory then seeders.
Now open DatabaseSeeder.php file and write the following codes.


namespace Database\\Seeders;

use Illuminate\\Database\\Seeder;

class DatabaseSeeder extends Seeder
* Seed the application's database.
* @return void
public function run()

Alright, now lets run the migration and then run the database seeder.

php artisan migrate;

Now run the seeder.

php artisan db:seed

Now switch to the project now just go inside the Users.php component class file write the following code.


namespace App\\Http\\Livewire;

use App\\Models\\User;
use Livewire\\Component;

class Users extends Component
public $users;
public function render()
$this->users = User::all();
return view('livewire.user-component');

Now just open users.blade.php component view file and here add a table and show all users.

<div class=\"container\">
<div class=\"row\">
<div class=\"col-md-12\">
<div class=\"card\">
<div class=\"card-header\">
All Users
<div class=\"card-body\">
<table class=\"table table-striped\">
@foreach($users as $user)

Now its done. So lets check this.
So switch to browser and go to the url /users.
And here you can see the users list.
So in this way you can use database in livewire.