{"id":14974419,"url":"https://github.com/salmanzafar949/laravel-repository-pattern","last_synced_at":"2026-03-10T14:31:05.644Z","repository":{"id":41461654,"uuid":"203381934","full_name":"salmanzafar949/Laravel-Repository-Pattern","owner":"salmanzafar949","description":"Package that let's you Implement repository pattern with a single command","archived":false,"fork":false,"pushed_at":"2022-05-17T04:01:40.000Z","size":10,"stargazers_count":8,"open_issues_count":0,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-22T18:08:08.186Z","etag":null,"topics":["laravel","laravel5","php","php7"],"latest_commit_sha":null,"homepage":"https://packagist.org/packages/salmanzafar/laravel-repository-pattern","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/salmanzafar949.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"custom":["paypal.me/salmanzafar949"]}},"created_at":"2019-08-20T13:27:56.000Z","updated_at":"2023-06-01T03:56:53.000Z","dependencies_parsed_at":"2022-09-02T17:14:24.697Z","dependency_job_id":null,"html_url":"https://github.com/salmanzafar949/Laravel-Repository-Pattern","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/salmanzafar949/Laravel-Repository-Pattern","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/salmanzafar949%2FLaravel-Repository-Pattern","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/salmanzafar949%2FLaravel-Repository-Pattern/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/salmanzafar949%2FLaravel-Repository-Pattern/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/salmanzafar949%2FLaravel-Repository-Pattern/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/salmanzafar949","download_url":"https://codeload.github.com/salmanzafar949/Laravel-Repository-Pattern/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/salmanzafar949%2FLaravel-Repository-Pattern/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261338979,"owners_count":23143896,"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":["laravel","laravel5","php","php7"],"created_at":"2024-09-24T13:50:31.936Z","updated_at":"2025-10-24T00:46:44.885Z","avatar_url":"https://github.com/salmanzafar949.png","language":"PHP","funding_links":["paypal.me/salmanzafar949"],"categories":[],"sub_categories":[],"readme":"# Laravel Repository Pattern Implementation\n\nA simple Laravel 5 and laravel 6 library that allows you to implement Repository Pattern with a single command\n\n## Installation\n```\ncomposer require salmanzafar/laravel-repository-pattern\n```\n\n## Features\n\nWill generate all the functionality for Repository pattern implementation\n\n* ServiceClass\n* Interface\n* ServiceProvider\n\n## Enable the package (Optional)\nThis package implements Laravel auto-discovery feature. After you install it the package provider and facade are added automatically for laravel \u003e= 5.5.\n\n## Configuration\nPublish the configuration file\n\nThis step is required\n\n```\nphp artisan vendor:publish --provider=\"Salman\\RepositoryPattern\\RepositoryPatterServiceProvider\"\n```\n\n## Usage\n\nAfter publishing the configuration file just run the below command\n\n```\nphp artisan make:repo ModelName\n```\n\nThat's it, Now you've successfully implemented the repository pattern\n\n## Example\n\n```php\nphp artisan make:repo Car\n```\n\n#### CarRepositoryInterface.php\n```php\n\u003c?php\n\nnamespace App\\Repositories;\n\ninterface CarRepositoryInterface\n{\n    /**\n     * Get's a record by it's ID\n     *\n     * @param int\n     */\n    public function get($id);\n\n    /**\n     * Get's all records.\n     *\n     * @return mixed\n     */\n    public function all();\n\n    /**\n     * Deletes a record.\n     *\n     * @param int\n     */\n    public function delete($id);\n\n    /**\n     * Updates a record.\n     *\n     * @param int\n     * @param array\n     */\n    public function update($id, array $data);\n}\n```\n\n#### CarRepository.php\n```php\n\u003c?php\n\nnamespace App\\Repositories;\n\nuse App\\Car;\n\n\nclass CarRepository implements CarRepositoryInterface\n{\n    /**\n     * Get's a record by it's ID\n     *\n     * @param int\n     * @return collection\n     */\n    public function get($id)\n    {\n        return Car::find($id);\n    }\n\n    /**\n     * Get's all records.\n     *\n     * @return mixed\n     */\n    public function all()\n    {\n        return Car::all();\n    }\n\n    /**\n     * Deletes a record.\n     *\n     * @param int\n     */\n    public function delete($id)\n    {\n        Car::destroy($id);\n    }\n\n    /**\n     * Updates a post.\n     *\n     * @param int\n     * @param array\n     */\n    public function update($id, array $data)\n    {\n        Car::find($id)-\u003eupdate($data);\n    }\n}\n```\n\n##### Now go to \n```Repositories/RepositoryBackendServiceProvider.php```\n and register the interface and class you have'just created\n\n```php\n\u003c?php\n\nnamespace App\\Repositories;\n\nuse Illuminate\\Support\\ServiceProvider;\n\nclass RepositoryBackendServiceProvider extends ServiceProvider\n{\n\n    public function register()\n    {\n        $this-\u003eapp-\u003ebind(\n            /*\n            * Register your Repository classes and interface here\n            **/\n\n            'App\\Repositories\\CarRepositoryInterface',\n            'App\\Repositories\\CarRepository'\n        );\n    }\n}\n\n```\n##### And now in your ```app/Http/Controllers/Carcontroller```\n\n```php\n\u003c?php\n\nnamespace App\\Http\\Controllers;\n\nuse App\\Car;\nuse App\\Repositories\\CarRepositoryInterface;\n\nclass CarController extends Controller\n{\n    protected $car;\n\n    public function __construct(CarRepositoryInterface $car)\n    {\n        $this-\u003e$car = $car;\n    }\n\n    /**\n     * Display a listing of the resource.\n     *\n     * @return \\Illuminate\\Http\\Response\n     */\n    public function index()\n    {\n        $data = $this-\u003ecar-\u003eall();\n\n        return $data;\n    }\n    \n}\n```\n\n\n\n##### That's it you've successfully implemented Repository pattern in your code.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsalmanzafar949%2Flaravel-repository-pattern","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsalmanzafar949%2Flaravel-repository-pattern","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsalmanzafar949%2Flaravel-repository-pattern/lists"}