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)

Model in Laravel

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.


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!


Comments and Discussions!

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.