In this video we are going to learn about model.
Model is a class that represents the logical structure and relationship of underlying data table.
In Laravel, each of the database table has a corresponding Model, that allow us to interact with that table.
Models gives you the way to retrieve, insert, and update information into your data table.
In previous tutorial we have created posts table in database.
Inside the table there are some posts here ok.
Now lets create a model for the Posts table.
So go to the command prompt and here run the command.

php artisan make:model Post

Naming Conventions for model is a model should be in singular, no spacing between words, and capitalised.
Here Post is a model name.
Alright, model has been created inside the app\\Models directory.
Lets see this go to the app\\Models directory and here you can see the Post model.
Just open this Post model.
And inside this post model class.
Just specify the table name So, just type here.


protected $table = 'posts';


Alright, Now lets see how can we use this model inside the controller.
So switch to the PostController and here import the Post model first.
For that before the class just add the following code.


use App\\Models\\Post;


Now we can use this post model.
So lets create a method for fetching all the post from the posts table.

public function getAllPostsUsingModel()
{
$posts = Post::all();
retrun $posts;
}


Now create routes for this.
So, Go to the web.php file and here type.

Route::get('/all-posts','[PostController::class, 'getAllPostsUsingModel');

Now save this file and.
Go to the browser and here.
Just type in the url.
/all-posts.
Now you can see here all the posts.
So in this way you can create and use model in laravel 8.