为 Laravel 模型设置列字段。

huangapple go评论50阅读模式
英文:

Setting the column fields for a laravel model

问题

在另一个类似Django的MVC框架中,我们可以通过在相应的模型类中定义属性来定义列字段。

在Laravel中如何做到这一点?

class Model {
    protected $fillable = [
        'name', 'address'
    ];
}

在模型类中,我们可以声明数据库的列和其数据类型。

在Laravel中如何做到这一点?

英文:

In another mvc framework like django,we can define the column fields by defining the attributes in the corresponding model clas.

How to do that in laravel?

class Model {
              name : string;
              address:string;
    }

In the model class we can declare the column for the database and its data type ?

How to do that in laravel?

答案1

得分: 0

也许可以查看 官方 Laravel 文档(eloquent 部分,ORM),如果你使用 Laravel。你不是在你的模型中定义它,而是在迁移中创建一个表格来存储你的模型数据。

关于迁移,请参阅 Laravel 迁移文档

英文:

Maybe have a look at the official Laravel docs (eloquent section, ORM) if you use Laravel. You don't define that in your Model, but in a migration, that is creating a table for your Model data.

For migrations, see Laravel Migrations

huangapple
  • 本文由 发表于 2023年4月10日 18:19:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/75976230.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定