offworks/laraquent

基于Laravel Eloquent 5.1扩展使用的库,可作为不同微框架的提供者。

v1.1.0 2019-07-29 08:08 UTC

This package is not auto-updated.

Last update: 2024-09-17 07:33:22 UTC


README

Laravel Eloquent 5.5的快速设置。

我只是太懒了,不想再次弄清楚我需要使用Eloquent的所有内容。 :p

更多文档可以在以下链接找到

用法

通过composer安装

composer require offworks/laraquent

启动

$capsule = \Laraquent\Factory::boot([
    'host' => 'localhost',
    'name' => 'mydb',
    'user' => 'root',
    'pass' => ''
    ]);

激活模式迁移

table()方法现在可以用来监听现有数据库,执行创建或修改表,将根据需要进行数据库更改。

  • 如果表不存在,则创建表。
  • 为现有表添加列,并在表不存在时跳过异常
  • 不会删除表
  • 不会删除列
$schema = new \Laraquent\Schema($capsule->getConnection());

$schema->table('Book', function($table) {
    $table->increments('id');
    $table->string('title');
    $table->string('isbn');
    $table->timestamps();
});

前缀关系方法

如果使用扩展的基本模型,关系方法现在应以'relate'前缀。例如

class Article extends \Laraquent\Entity
{
    public function relateAuthor()
    {
        return $this->hasOne('\App\Entity\Author', 'author_id');
    }
}

特别感谢

特别感谢Taylor Otwell和Laravel社区,他们打造了一个出色的框架,并使得在Laravel之外使用Eloquent成为可能。