{"id":22208649,"url":"https://github.com/zqhong/fastd-eloquent","last_synced_at":"2025-07-27T09:30:44.263Z","repository":{"id":57092043,"uuid":"95755978","full_name":"zqhong/fastd-eloquent","owner":"zqhong","description":null,"archived":false,"fork":false,"pushed_at":"2022-10-25T02:58:38.000Z","size":29,"stargazers_count":10,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2023-11-20T15:02:33.477Z","etag":null,"topics":["db","eloquent","fastd"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zqhong.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-06-29T08:29:48.000Z","updated_at":"2023-11-14T05:33:45.000Z","dependencies_parsed_at":"2022-08-22T20:40:53.608Z","dependency_job_id":null,"html_url":"https://github.com/zqhong/fastd-eloquent","commit_stats":null,"previous_names":[],"tags_count":12,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zqhong%2Ffastd-eloquent","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zqhong%2Ffastd-eloquent/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zqhong%2Ffastd-eloquent/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zqhong%2Ffastd-eloquent/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zqhong","download_url":"https://codeload.github.com/zqhong/fastd-eloquent/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227786946,"owners_count":17819797,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["db","eloquent","fastd"],"created_at":"2024-12-02T19:21:19.151Z","updated_at":"2024-12-02T19:21:20.651Z","avatar_url":"https://github.com/zqhong.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fastD Eloquent\n使用 Eloquent 替换 fastD 自带的 [Medoo](https://medoo.in/)\n\n## 安装\n```bash\n$ composer require -vvv zqhong/fastd-eloquent\n```\n\n## 配置\n修改配置文件 `config/app.conf`，添加 `EloquentServiceProvider`，如下：\n```php\n\u003c?php\nreturn [\n    // 省略了无关配置\n    'services' =\u003e [\n        \\ServiceProvider\\EloquentServiceProvider::class,\n    ],\n];\n```\n\n修改配置文件 `.env.yml`，添加如下信息：\n```yaml\ndatabase:\n    default:\n        adapter: db_adapter\n        name: db_name\n        host: db_host\n        user: db_username\n        pass: db_password\n        charset: db_charset\n        port: db_port\n        prefix: db_prefix\n```\n\n其中，`driver` 的可选值为：`mysql`、`pgsql`、`sqlite` 和 `sqlsrv`。\n\n## 直接使用\n```php\n\u003c?php\n\u003c?php\n\nuse Illuminate\\Database\\Capsule\\Manager;\n\n// create\nManager::connection('default')\n    -\u003etable('demo')\n    -\u003einsert([\n        'content' =\u003e 'hello world',\n    ]);\n\n// read\n// 参数一可省略，默认值为 default\nManager::connection('default')\n    -\u003etable('demo')\n    -\u003ewhere('id', 1)\n    -\u003ewhere('created_at', '\u003c=', time())\n    -\u003eget([\n        'id',\n        'content',\n    ]);\n\n// update\nManager::connection('default')\n    -\u003etable('demo')\n    -\u003ewhere('id', 1)\n    -\u003eupdate([\n        'content' =\u003e 'hello 2',\n    ]);\n\n// delete\nManager::connection('default')\n    -\u003etable('demo')\n    -\u003ewhere('id', 1)\n    -\u003edelete();\n\n```\n\n## 配置 Model 使用\n```php\n\u003c?php\n\nnamespace Model;\n\nuse Illuminate\\Database\\Eloquent\\Model;\n\nclass DemoModel extends Model\n{\n    public $table = 'demo';\n\n    public static function fetchAll()\n    {\n        return static::query()\n            -\u003eget()\n            -\u003etoArray();\n    }\n}\n```\n\n## 分页\n### 分页的简单使用\n```php\n\u003c?php\n$perPage = 10;\n$columns = ['*'];\n$pageName = 'page';\n\n$paginator = YourModel::query()-\u003epaginate($perPage, $columns, $pageName);\n$data = $paginator-\u003etoArray();\n\n// 注：page 参数（当前页）会自动从 $_GET 或 $_POST 中的 page 参数自动获取，不需要单独设置。\n// 参考代码\n//LengthAwarePaginator::currentPageResolver(function () {\n//    return (int)Arr::get(array_merge($_GET, $_POST), 'page', 1);\n//});\n```\n\n\n## 其他资源\n如果你对在其他框架中使用 Eloquent 感兴趣，请参考 Slim 的这篇文章 - [Using Eloquent with Slim](https://www.slimframework.com/docs/cookbook/database-eloquent.html)。\n\n如果你对 Eloquent 不熟悉，请阅读下面的资料。\n* [Laravel - Database: Query Builder](https://laravel.com/docs/5.4/queries)\n* [Laravel - Database: Pagination](https://laravel.com/docs/5.4/pagination)\n* [Laravel - Eloquent: Getting Started](https://laravel.com/docs/5.4/eloquent)\n* [Laravel - Eloquent: Collections](https://laravel.com/docs/5.4/eloquent-collections)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzqhong%2Ffastd-eloquent","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzqhong%2Ffastd-eloquent","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzqhong%2Ffastd-eloquent/lists"}