The MorphOne field corresponds to a morphOne Eloquent relationship. For example, let’s assume a Post has a one-to-one polymorphic relationship with the Image model. We may add the relationship to our Post Nova
Rache1 未填写
所有Eloquent 查询回传的数据,如果结果多于一条,不管是经由 get 方法或是 relationship,都会转换成 collection 对象回传。这个对象实现了 IteratorAggregate PHP 接口,所以可以像数组一般进行遍历。而 Collections 对象本身还拥有很多有用的方法可以操作模型数据。
所有Eloquent 查询回传的数据,如果结果多于一条,不管是经由 get 方法或是 relationship,都会转换成 collection 对象回传。这个对象实现了 IteratorAggregate PHP 接口,所以可以像数组一般进行遍历。而 Collections 对象本身还拥有很多有用的方法可以操作模型数据。
所有通过 get 方法或一个relationship由Eloquent返回的多结果集都是一个集合对象。这个对象实现了 IteratorAggregate PHP 接口,所以可以像数组一样进行遍历。然而,这个对象也有很多其他的函数来处理结果集。比如,我们可以使用 contains 检测一个结果集是否包含指定的主键:...
要确认模型是否被软删除了,可以使用 trashed 方法:if ($user->trashed()){ //}时间戳默认Eloquent 会自动维护数据库表的 created_at 和updated_at 字段。只要把这两个「时间戳」字段加到数据库表, Eloquent 就会处理剩下的工作。如果不想让 Eloquent 自动维护这些字段,把下面的属性加到模型类里:...
This allows this developer to // include deleted model in a relationship result set that is lazy loaded. if ($this->isSoftDeleteConstraint($where, $column)) { unset($query->wheres[$key]); $query->wheres = array_values($query->wheres); } } }Copy...
For example, you may wish to only disable lazy loading in non-production environments so that your production environment will continue to function normally even if a lazy loaded relationship is accidentally present in production code. Typically, this method should be invoked in the boot method of...
The withTrashed method may also be used on arelationshipquery: $flight->history()->withTrashed()->get(); Retrieving Only Soft Deleted Models The onlyTrashed method will retrieveonlysoft deleted models: $flights = App\Flight::onlyTrashed() ...
我们先从建立一个 Eloquent 模型开始。模型通常放在app目录下,但是您可以将它们放在任何地方,只要能通过 composer.json 自动载入。所有的 Eloquent 模型都继承于Illuminate\Database\Eloquent\Model。 定义一个 Eloquent 模型 classUserextendsModel{} 你也可以通过make:model命令自动生成 Eloquent 模型: ...