{"id":36988519,"url":"https://github.com/eghamat24/database-repository","last_synced_at":"2026-01-13T23:26:14.415Z","repository":{"id":43725014,"uuid":"465249823","full_name":"eghamat24/database-repository","owner":"eghamat24","description":"Create Repository Base Data Access for Laravel \u0026 Lumen","archived":false,"fork":false,"pushed_at":"2025-03-05T13:25:53.000Z","size":238,"stargazers_count":19,"open_issues_count":4,"forks_count":8,"subscribers_count":2,"default_branch":"master","last_synced_at":"2026-01-13T22:40:49.799Z","etag":null,"topics":["laravel","laravel-package","laravel-repository","laravel-repository-pattern","lumen","php","repository","repository-pattern"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eghamat24.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-03-02T10:02:10.000Z","updated_at":"2025-12-16T20:15:59.000Z","dependencies_parsed_at":"2024-05-12T16:25:26.829Z","dependency_job_id":"c32f34b9-edcb-4da3-b630-1cf77a17a238","html_url":"https://github.com/eghamat24/database-repository","commit_stats":null,"previous_names":["iran-coders/database-repository","eghamat24/database-repository"],"tags_count":31,"template":false,"template_full_name":null,"purl":"pkg:github/eghamat24/database-repository","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eghamat24%2Fdatabase-repository","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eghamat24%2Fdatabase-repository/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eghamat24%2Fdatabase-repository/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eghamat24%2Fdatabase-repository/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eghamat24","download_url":"https://codeload.github.com/eghamat24/database-repository/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eghamat24%2Fdatabase-repository/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28405246,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-13T21:51:37.118Z","status":"ssl_error","status_checked_at":"2026-01-13T21:45:14.585Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: 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":["laravel","laravel-package","laravel-repository","laravel-repository-pattern","lumen","php","repository","repository-pattern"],"created_at":"2026-01-13T23:26:13.825Z","updated_at":"2026-01-13T23:26:14.409Z","avatar_url":"https://github.com/eghamat24.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Database Repository / PHP Repository / Laravel Repository\n\n## Installation\nUse the following command to add this package to the composer development requirement.\n```bash\ncomposer require eghamat24/database-repository --dev \n```\n\n### Setup Laravel Repository\nThen run the following command in the console to publish the necessary assets in your project directory. \n```bash\nphp artisan vendor:publish --tag=database-repository-config\n```\n\n### Setup Lumen Repository\nNavigate to `app.php` in `bootstrap` folder and add the following line after service providers registrations:\n```php\n// snip\nif ($app-\u003eenvironment('local', 'testing')) {\n    $app-\u003eregister(Eghamat24\\DatabaseRepository\\DatabaseRepositoryServiceProvider::class);\n}\n// snip\n```\nCopy [repository.php](config/repository.php) to the project config folder located at the project root.\n\nNote: Make sure to run `composer dump-autoload` after these changes.\n\n## Usage\nTo use this package easily, you can run the following command. It will create all the required components such as Entity, IRepository, Repository, MySqlRepository, RedisRepository, Resource, and Factory for the users table.\n```bash\nphp artisan repository:make-all --table_names=users --strategy_name=QueryCacheStrategy\n```\nList of artisan commands:\n\n| Command                                | Inputs                                                                    | Options            | Description                       |\n|----------------------------------------|---------------------------------------------------------------------------|--------------------|-----------------------------------|\n| `repository:make-entity`               | table_name                                                                | -f, -d, -k, -g     | Create new Entity                 |\n| `repository:make-enum`                 | table_name                                                                | -f, -d, -g         | Create new Enum                   |\n| `repository:make-factory`              | table_name                                                                | -f, -d, -g         | Create new Factory                |\n| `repository:make-resource`             | table_name                                                                | -f, -d, -k, -g     | Create new Resource               |\n| `repository:make-interface-repository` | table_name                                                                | -f, -d, -k, -g     | Create new Repository Interface   |\n| `repository:make-repository`           | table_name, selected_db(optional)                                         | -f, -d, -k, -g     | Create new Base Repository        |\n| `repository:make-mysql-repository`     | table_name                                                                | -f, -d, -k, -g     | Create new MySql Repository class |\n| `repository:make-redis-repository`     | table_name                                                                | -f, -d, -k, -g     | Create new Redis Repository class |\n| `repository:make-all`                  | --table_names=table_names(optional) \u003cbr/\u003e--selected_db=database(optional) | -a, -f, -d, -k, -g | Run all of the above commands     |\n\n\n### Options Explanation\n- `-f|--force`: Force commands to override existing files.\n- `-d|--delete`: Delete already created files.\n- `-k|--foreign-keys`: Try to detect foreign keys of a table.\n- `-g|--add-to-git`: Add created files to the git repository.\n- `-a|--all-tables`: Use all existing tables.\n- `--table_names=`: Add table names, separate names with comma.\n- `--selected_db=` : Use between `Mysql`,`Redis`, If it does not send, the value will return from `config/repository.php`\n- `--strategy_name=` : add a trait to your Redis repository based on the strategy you choose\n\nExample 1. Create a new Entity for a table named 'users'.\n```bash\nphp artisan repository:make-entity users\n```\n\nExample 2. Create all necessary classes for two tables named 'users' and 'customers' with an enabled foreign key option.\n```bash\nphp artisan repository:make-all --table_names=users,customers -k\n```\n\nExample 3. Create all necessary classes for all tables with an enabled foreign key option(this may be used for new projects).\n```bash\nphp artisan repository:make-all -a -k\n```\n\n## Cache Strategy\nWe created some strategies for caching data, based on the number of records and change frequency\n\n### SingleKeyCacheStrategy\nSingleKeyCacheStrategy is a good choice for tables with very few rows, such as less than 50 records. This strategy creates one cache key and stores all the data on it. Then, when the app queries data, it loops through the data and returns the result.\n\nThis strategy has one cache key and clears all the cached data whenever there is a change. This ensures that the data is always updated and valid.\n\n### QueryCacheStrategy\nQueryCacheStrategy is suitable for tables that have low change frequency and not too many records. For example, if the table has less than 10,000 rows or if it has more than that but the queries are not very unique and there are similar queries, this strategy works well.\n\nThis strategy assigns a tag to each cache of the repository and clears all the cached data whenever there is a change. This ensures that the data is always updated and valid.\n\n### TemporaryCacheStrategy\nTemporaryCacheStrategy is useful when we have a large or diverse amount of data and the data user can tolerate some delay in the updates. We cache every request and delay the changes that are not critical to be reflected in real time. For example, if we have a post and we edit its content, we can cache the old version until the cache expires. We set the cache expiration time for each data item based on the maximum delay the user can accept. This way, we use this strategy to cache data temporarily.\n\n### ClearableTemporaryCacheStrategy\nSometimes, we need to clear the data from a temporary cache when some critical changes occur. ClearableTemporaryCacheStrategy is suitable for these situations.\n\n```bash\nphp artisan repository:make-all --table_names=users --strategy_name=QueryCacheStrategy\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feghamat24%2Fdatabase-repository","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feghamat24%2Fdatabase-repository","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feghamat24%2Fdatabase-repository/lists"}