Home »
Laravel
Model in Laravel
In this article, we are going to discuss how to work with Laravel? Here, we see how to make a model in Laravel?
Submitted by Bharti Parmar, on November 16, 2019
For further process we need to know something about it,
- We are creating a model in Laravel just because of creating a logical structure and relation between them.
- The model handles the MVC framework which is based on the web-based application.
- Each database has a model that is used to interact with another table.
Model in Laravel
Now, create new model named 'post' model,
Open the CMD and run this command for creating a model: $ php artisan make:model Post
Path: app/providers/post.php (declare our table if your table is not procedural)
Example: Model/post.php
Class Post extends Model
{
Protected $PrimaryKey = 'id';
Protectted $table = 'posts';
Protected $fillable = ['title','body'];
}
Here, $table is a table name. In the Model primary key is by default id.
Protected $PrimaryKey ="id"
$fillable is another variable in Laravel because we have to fill or insert the data in title and body columns. It's a column variable name only.
Conclusion:
In this article, we have learnt about the model in Laravel. I hope you understood the concept, we will know more about it in the up coming articles. Have a great day! Happy Learning!