laravel模型_Laravel模型

laravel模型

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.

    我们之所以在Laravel中创建模型,是因为它们之间建立了逻辑结构和关系。

  • The model handles the MVC framework which is based on the web-based application.

    该模型处理基于Web应用程序的MVC框架。

  • Each database has a model that is used to interact with another table.

    每个数据库都有一个用于与另一个表进行交互的模型。

Laravel模型 (Model in Laravel)

Now, create new model named 'post' model,

现在,创建一个名为“ post”模型的新模型,

Open the CMD and run this command for creating a model: $ php artisan make:model Post

打开CMD并运行以下命令来创建模型: $ php artisan make:model Post

Path: app/providers/post.php (declare our table if your table is not procedural)

路径app / providers / post.php(如果您的表不是程序性的,则声明我们的表)

Model in Laravel

Example: Model/post.php

示例: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.

在这里, $ table是一个表名。 在Model中,主键默认为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.

$ fillable是Laravel中的另一个变量,因为我们必须在title和body列中填充或插入数据。 它仅是列变量名称。

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!

在本文中,我们了解了Laravel中的模型。 希望您理解这个概念,我们将在以后的文章中进一步了解它。 祝你有美好的一天! 学习愉快!

翻译自: https://www.includehelp.com/laravel/model.aspx

laravel模型

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值