{"id":15293889,"url":"https://github.com/pacerit/laravel-core","last_synced_at":"2026-01-14T01:33:09.344Z","repository":{"id":35035306,"uuid":"199045038","full_name":"pacerit/laravel-core","owner":"pacerit","description":"Package of core classes that provide standardization in usage of Services, Repositories etc. for Laravel framework.","archived":true,"fork":false,"pushed_at":"2022-02-16T21:10:33.000Z","size":157,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-10-07T06:37:10.902Z","etag":null,"topics":["entity","formatter","laravel","laravel-framework","php","repository","services","trait"],"latest_commit_sha":null,"homepage":"","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/pacerit.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-07-26T15:59:35.000Z","updated_at":"2023-09-09T17:03:27.000Z","dependencies_parsed_at":"2022-08-08T04:01:02.056Z","dependency_job_id":null,"html_url":"https://github.com/pacerit/laravel-core","commit_stats":null,"previous_names":[],"tags_count":42,"template":false,"template_full_name":null,"purl":"pkg:github/pacerit/laravel-core","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pacerit%2Flaravel-core","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pacerit%2Flaravel-core/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pacerit%2Flaravel-core/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pacerit%2Flaravel-core/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pacerit","download_url":"https://codeload.github.com/pacerit/laravel-core/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pacerit%2Flaravel-core/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28408580,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T00:40:43.272Z","status":"ssl_error","status_checked_at":"2026-01-14T00:40:42.636Z","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":["entity","formatter","laravel","laravel-framework","php","repository","services","trait"],"created_at":"2024-09-30T16:53:35.640Z","updated_at":"2026-01-14T01:33:09.317Z","avatar_url":"https://github.com/pacerit.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel Core\n![GitHub tag (latest by date)](https://img.shields.io/github/tag-date/pacerit/laravel-core?label=Version)\n![GitHub](https://img.shields.io/github/license/pacerit/laravel-core?label=License)\n![Packagist](https://img.shields.io/packagist/dt/pacerit/laravel-core?label=Downloads)\n![PHP from Packagist](https://img.shields.io/packagist/php-v/pacerit/laravel-core?label=PHP)\n[![StyleCI](https://github.styleci.io/repos/199045038/shield?branch=master)](https://github.styleci.io/repos/199045038)\n[![Build Status](https://travis-ci.com/pacerit/laravel-core.svg?branch=master)](https://travis-ci.com/pacerit/laravel-core)\n\nPackage of core classes that provide standardization in usage of Services, Repositories etc. for Laravel and\nLumen framework.\n\n## Installation\nYou can install this package by composer:\n\n    composer require pacerit/laravel-core\n    \n### Version compatibility\n#### Laravel\nFramework | Package | Note\n:---------|:--------|:------\n5.8.x     | ^1.x.x  | No longer maintained.\n6.0.x     | ^2.x.x  | Bug fixes only.\n7.x.x     | ^3.x.x  | Bug fixes only.\n8.x.x     | ^4.x.x  | PHP ^8.0 Supported from 4.0.4\n9.x.x     | ^5.x.x  |\n\n#### Lumen\nFramework | Package | Note\n:---------|:--------|:------\n5.8.x     | ^1.1.x  | No longer maintained.\n6.0.x     | ^2.x.x  | Bug fixes only.\n7.x.x     | ^3.x.x  | Bug fixes only.\n8.x.x     | ^4.x.x  | PHP ^8.0 Supported from 4.0.4\n9.x.x     | ^5.x.x  |\n\n## Classes included\n\n### Basic classes\n    CoreEntity::class - base class models\n    CoreRepository::class - base class of repositories (provided by package)\n    CoreService::class - base class of services\n    CoreFormatter::class - base class of formatter\n    CoreException::class - base class of exceptions\n        \n### Traits\n    ScenatioTrait::class\n    StringTrait::class\n    NumberTrait::class\n    XMLTrait::class\n    \n## Implementation\n\n### Entities implementation\nIn order to use Service, Repositories or Formatter classes, first you must prepare your entities. Every entity\nin you application must:\n- Extend CoreEntity class\n- Implements interface that extend CoreEntityInterface\n\nFor example, this is implementation of Example entity:\n\nExample class:\n```php\nclass Example extends CoreEntity implements ExampleInterface\n{}\n```\n\nExampleInterface:\n```php\ninterface ExampleInterface extends CoreEntityInterface\n{}\n```\nInterface and entity class must be bind in you app ServiceProvider:\n```php\n/**\n * Register any application services.\n *\n * @return void\n */\npublic function register()\n{\n    $this-\u003eapp-\u003ebind(ExampleInterface::class, Example::class);\n}\n```\n\n#### Using UUID's in Entity\n**To use UUID feature install suggested ramsey/uuid package**\n\nThis package provides possibility to use UUID's in Entities as secondary key, for external use (i.e. in routes). \nIt still requires to use integer type ID's as Primary keys in your database.\n\nTo use UUID's in your Entity, it must:\n- Implements UUIDInterface\n- Use UsesUUID trait\n\nIn your migration create field with \"uuid\" key using uuid() method.\n```php\n$table-\u003euuid(UsesUUID::UUID);\n```\nUUID's will bu automatically generated when new entity is created.\nIf you use Services, you can add WithUUID trait to your implementation of CoreService class to add methods that \nare helpful when using UUID's.\n```php\nclass MyEntityService extends CoreService implements MyEntityServiceInterface\n    use WithUUID;\n    (...)\n```\n\n### Repositories implementation and usage\n\nDocumentation of Repository can be found [here.](https://github.com/pacerit/laravel-repository)\n\n### Services implementation\nTo use Service, create service class that:\n- Extend CoreService class\n- Implements interface that extend CoreServiceInterface\n\nFor example, this is implementation of service for Example entity:\n\nExampleServiceInterface:\n```php\ninterface ExampleServiceInterface extends CoreRepositoryInterface\n{}\n```\nExampleService class. In __construct() function of class, provide class of repository for entity, and set it by\nsetRepository() function. Optionally you can pass formatter for entity and set if by setFormattter() function\nto provide formatting functionality.\nProvided classes must be implementation of CoreRepository/CoreFormatter.\n```php\nclass ExampleService extends CoreService implements ExampleServiceInterface\n{\n    /**\n     * ExampleService constructor.\n     *\n     * @param ExampleRepositoryInterface $exampleRepository\n     * @param ExampleFormatterInterface $exampleFormatter\n     */\n    public function __construct(\n        ExampleRepositoryInterface $exampleRepository,\n        ExampleFormatterInterface $exampleFormatter\n    ) {\n        $this-\u003esetRepository($exampleRepository)\n            -\u003esetFormatter($exampleFormatter);\n    }\n\n}\n```\n#### Using services\nTo use Service in controller or other class you can use dependency injection or Container. Below is sample code of\nusing service in controller.\n```php\nclass ExampleController extends Controller {\n\n    /**\n     * @var ExampleServiceInterface $exampleService\n     */\n    protected $exampleService;\n\n    public function __construct(ExampleServiceInterface $exampleService){\n        $this-\u003eexampleService = $exampleService;\n    }\n\n    ....\n}\n```\n#### Available methods\n* setRepository() - set repository to use in service. Passing object must be implementation of CoreRepositoryInterface\n* getRepository() - return previously set repository class instance\n* setFormatter() - set formatter class to use in service. Passing object must be implementation of \nCoreFormatterInterface\n* getFormatter() - return previously set formatter class instance\n* setModel() - set model you want to work on i.e. if you already have instance\n* setModelByID() - set model by given id (integer). If model with given ID exist, it will be set, otherwise exception\nwill by thrown\n* setModelByKey() - set model by given key (column in table) and given value. Helpful when looking for record by column\nother than ID (i.e foreign key)\n* setNewMode() - set new model class instance\n* getModel() - get previously set model class instance\n* format() - get previously set model class instance and pass it to formatter class. CoreFormatterInterface instance\nwill be return. Example of use.\n```php\n// Return Example entity record with ID 1 as an array.\nreturn $this-\u003eexampleService-\u003esetModelByID(1)-\u003eformat()-\u003etoArray();\n```\n* create() - create new entity record based on actually set model, of given parameters. Example:\n```php\nFor this example, we assume that Example entity class have setFirstValue() and setSecondValue() functions (setters)\nand const. Both of this example, create the same records in database.\n\n// Create based on previously set entity.\n$this-\u003eexampleService\n    -\u003esetNewModel()\n    -\u003egetModel()\n    -\u003esetFirstValue(1)\n    -\u003esetSecondValue(2);\n\n$this-\u003eexampleService-\u003ecreate();\n\n// Create model based on parameters.\n$this-exampleService-\u003ecreate(\n    [\n        ExampleInterface::FIRST_VALUE =\u003e 1,\n        ExampleInterface::SECOND_VALUE =\u003e 2,\n    ]\n);\n\n```\n* update() - update model. Like in create method it base on previously set model or parameters, but we must set existing\nmodel record before. Otherwise exception will be thrown. Example:\n```php\n// Update based on previously set entity.\n$this-\u003eexampleService\n    -\u003esetModelByID(1)\n    -\u003egetModel()\n    -\u003esetFirstValue(2);\n\n$this-\u003eexampleService-\u003eupdate();\n\n// Update model based on parameters.\n$this-exampleService-\u003eupdate(\n    1,\n    [\n        ExampleInterface::FIRST_VALUE =\u003e 2,\n    ]\n);\n```\n* delete() - delete model. Like in update() method, this also required to set existing model before.\n```php\n$this-\u003eexampleService-\u003esetModelByID(1)-\u003edelete();\n```\n## Traits\n### ScenarioTrait\nScenarioTrait contains very useful functions, if we want use different class, based by some key (i.e. \"type\" field\nin entity).\n\nFor example - we have abstract \"PaymentService\" class with not implemented \"create()\" method.\nWe create two classes that extend this class and implement create() function - each class for different\npayment provider:\n\n    * DummyProviderPaymentService::class - for \"DummyProvider\"\n    * OtherDummyProviderPaymentService::class - for \"OtherDummyProvider\"\n    \neach of them implements the create() function a little differently.\n\nNormally if we want call create() function in matching class we will be do it like this:\n```php\n(...)\nswitch ($type) {\n    case 'DummyProvider':\n        $service = new DummyProviderPaymentService::class;\n        break;\n\n    case 'OtherDummyProvider':\n        $service = new OtherDummyProviderService::class;\n        break;  \n    \n     default:\n        // Dunno what to do..\n}\n\n$service-\u003ecreate();\n(...)\n```\n\nBut if this class have dependency injection, that is not possible. And is not very elegant.\n\nHere comes help from ScenarioTrait. With this class, we can solve this problem, \nfor example, in this way:\n```php\n(...)\n$this-\u003eregisterScenario('DummyProvider', DummyProviderPaymentService::class);\n$this-\u003eregisterScenatio('OtherDummyProvider', OtherDummyProviderService::class);\n\n$this-\u003egetScenatioInstance($type)-\u003ecreate();\n(...)\n```\nThat's it. And yes - we can pass only namespace of class (even with dependency injection) - new\ninstance will be created while call getScenarioInstance() method. Of course you can pass exist\ninstance of class (.i.e. from dependency injection) - it's up to you.\n\n## Changelog\n\nGo to the [Changelog](CHANGELOG.md) for a full change history of the package.\n\n## Testing\n\n    composer test\n\n## Security Vulnerabilities\n\nIf you discover a security vulnerability within package, please send an e-mail to Wiktor Pacer\nvia [kontakt@pacerit.pl](mailto:kontakt@pacerit.pl). All security vulnerabilities will be promptly addressed.\n\n## License\n\nThis package is open-source software licensed under the [MIT license](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpacerit%2Flaravel-core","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpacerit%2Flaravel-core","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpacerit%2Flaravel-core/lists"}