{"id":22056941,"url":"https://github.com/danteay/corephp-slim-elquent","last_synced_at":"2026-04-11T09:42:19.463Z","repository":{"id":56957962,"uuid":"173372812","full_name":"danteay/corephp-slim-elquent","owner":"danteay","description":"An Eloquent dependency wrapper for Slim 3","archived":false,"fork":false,"pushed_at":"2019-03-13T22:48:27.000Z","size":14,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-18T05:35:29.396Z","etag":null,"topics":["composer","database","eloquent","orm","php7","slim-3","slim-framework"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/danteay.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-03-01T21:52:08.000Z","updated_at":"2022-02-12T09:18:10.000Z","dependencies_parsed_at":"2022-08-21T09:50:16.199Z","dependency_job_id":null,"html_url":"https://github.com/danteay/corephp-slim-elquent","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/danteay/corephp-slim-elquent","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danteay%2Fcorephp-slim-elquent","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danteay%2Fcorephp-slim-elquent/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danteay%2Fcorephp-slim-elquent/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danteay%2Fcorephp-slim-elquent/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danteay","download_url":"https://codeload.github.com/danteay/corephp-slim-elquent/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danteay%2Fcorephp-slim-elquent/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31676210,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-11T08:18:19.405Z","status":"ssl_error","status_checked_at":"2026-04-11T08:17:08.892Z","response_time":54,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["composer","database","eloquent","orm","php7","slim-3","slim-framework"],"created_at":"2024-11-30T16:15:27.478Z","updated_at":"2026-04-11T09:42:19.445Z","avatar_url":"https://github.com/danteay.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Eloquent dependency wrapper for Slim 3\n\nThis is a simple wrapper of Eloquent ORM for Slim 3. It provides a Parser class to\ngenerate connections option from a standard database URL of PostgresSQL, MySQL or SQLite databases.\n\n## Dependencies\n\n* [illuminate/database](https://packagist.org/packages/illuminate/database)\n\n## Installation\n\nYou can use the [slimcmd](https://packagist.org/packages/corephp/slim-cmd) tool to install this dependency:\n\n```bash\nslimcmd dependency:add eloquent\n```\n\nOr you can setup manually:\n\n```bash\ncomposer require corephp/slim-eloquent\n```\n\n## Allowed Database URLs\n\nTe allowed formats of database connections are:\n\n### MySQL\n\n```bash\nmysql://user:password@host:post/database\n```\n\n### PostgreSQL\n\n```bash\npostgres://user:password@host:post/database\n```\n\n### SQLite\n\n```bash\nsqlite://pato/to.database\n```\n\n## Using Parser class\n\nThe Parser class has 3 available methods to generate conection opctions for Eloquent:\n\n* **parseConnection**: Parse connection strings for MySQL, PostgreSQL and SQLite connections.\n* **parseGeneral**: Parse connections for MySQL and PostgreSQL only.\n* **parseSqlite**: Parse connections for SQLite only.\n\nThe `parseConnection` and the `parseGeneral` function generates a configuration array as it shown below when pass a PostgreSQL or MySQL connection:\n\n```php\n$options = [\n    'driver'    =\u003e 'mysql|pgsql|sqlite',\n    'host'      =\u003e 'host',\n    'port'      =\u003e 3306,\n    'database'  =\u003e 'database',\n    'username'  =\u003e 'user',\n    'password'  =\u003e 'pass',\n    'charset'   =\u003e 'utf8mb4',\n    'collation' =\u003e 'utf8mb4_unicode_ci',\n];\n```\n\nThe `parseConnection` and the `parseSqlite` function generates a configuration array as shown below when pass a SQLite connection.\n\n```php\n$options = [\n    'driver' =\u003e 'sqlite',\n    'database' =\u003e '/path/to.database',\n    'foreign_key_constraints' =\u003e true,\n    'charset' =\u003e 'utf8mb4',\n    'collation' =\u003e 'utf8mb4_unicode_ci',\n];\n```\n\n### Examples\n\n```php\nuse CorePHP\\Slim\\Dependency\\Database\\Parser;\n\n$settings = [\n    // ...\n    \"database\" =\u003e Parser::parseConnection(\n        getenv('DATABASE_URL')\n    )\n    // ...\n];\n```\n\n## Eloquent Wrapper\n\nThis class allows you to create the main connection to embed as dependency on Slim.\nYou can generate a `database.php` file your dependencies section with the code below:\n\n```php\nuse CorePHP\\Slim\\Dependency\\Database\\Eloquent;\n\nreturn function ($container) {\n    $settings = $container-\u003eget('eloquent');\n    \n    $eloquent = new Eloquent();\n    $eloquent-\u003eaddConnection($settings);\n\n    return $eloquent-\u003egetManager();\n};\n```\n\nThis generates the main connection and boot Eloquent to use the models. Also you\ncan setup a read and write configuration with diferent databases.\n\n```php\nuse CorePHP\\Slim\\Dependency\\Database\\Eloquent;\n\nreturn function ($container) {\n    $eloquent = new Eloquent();\n    $eloquent-\u003eaddConnection($container['database'], 'default', 'r'); // read\n    $eloquent-\u003eaddConnection($container['database2'], 'default', 'w'); // write\n\n    return $eloquent-\u003egetManager();\n}\n```\n\n## Base Model class\n\nThis packages provides a predefined base model class that brings you the most\nbasic configuration of Models that you need and you can use it as shown below:\n\n```php\nuse CorePHP\\Slim\\Dependency\\Database\\Model;\n\nclass User extends Model\n{\n    protected $table = 'users';\n}\n```\n\nThe Model class has 2 preconfigured functions:\n\n* **getDateFormat**: Has the date format definition as 'Y-m-d H:i:s'\n* **scopePagination**: Scope that can be aded at the end of a chain of query\n  filters to generate paginated sections of a single query. This scope has 3\n  parameters: $limit, $page and $links in that order.\n  * `$limit`: Is the number of elements by page that will be retrived by the\n    query.\n  * `$page`: Page that will be retrived. I you set a number lower than 1, you\n    will always have the page 1, and if you set a number greater than the total\n    of pages, you will always have the last page posible.\n  * `$links`: this is a boolean parameter, if you set as true, this generates an\n    extra key on the resultant array named *links* that will have the pagination sections in an array like this: `[1, 2, 3, 4, 5, 6, '...', 100]`. this can Helpyou to generate a custom pagination for your datatables.\n\n### Pagination example\n\n```php\n$items = User::where('name', 'like', '%Jhon%')\n    -\u003epagination(10, 1, true);\n\n// The content of items variable will be:\n//\n// [\n//    \"data\" =\u003e [ ... ]\n//    \"pages\" =\u003e [\n//      \"limit\" =\u003e 10,\n//      \"pages\" =\u003e 100    /* depending of the total elemtns */\n//      \"total\" =\u003e 1000   /* total elemtns of the query */\n//      \"page\" =\u003e 1,\n//      \"links\" =\u003e [ 1, 2, 3, 4, 5, 6, '...', 100 ]\n//    ]\n// ]\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanteay%2Fcorephp-slim-elquent","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanteay%2Fcorephp-slim-elquent","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanteay%2Fcorephp-slim-elquent/lists"}