PHPackages                             pacerit/laravel-core - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. pacerit/laravel-core

AbandonedArchivedLibrary[Framework](/categories/framework)

pacerit/laravel-core
====================

Package of core classes that provide standardization in usage of Services, Repositories etc. for Laravel framework.

5.0.0(4y ago)6323MITPHPPHP ^8.0

Since Jul 26Pushed 4y ago2 watchersCompare

[ Source](https://github.com/pacerit/laravel-core)[ Packagist](https://packagist.org/packages/pacerit/laravel-core)[ RSS](/packages/pacerit-laravel-core/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (6)Versions (50)Used By (0)

Laravel Core
============

[](#laravel-core)

[![GitHub tag (latest by date)](https://camo.githubusercontent.com/827205262de139e15c1ee5d35b0c4380df5ef11b9971f42ed65bc6d6e2674a9f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f7461672d646174652f706163657269742f6c61726176656c2d636f72653f6c6162656c3d56657273696f6e)](https://camo.githubusercontent.com/827205262de139e15c1ee5d35b0c4380df5ef11b9971f42ed65bc6d6e2674a9f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f7461672d646174652f706163657269742f6c61726176656c2d636f72653f6c6162656c3d56657273696f6e)[![GitHub](https://camo.githubusercontent.com/b38b06f44728065e3b432140d1a476bc2f2570d1d08fc655425ca4191e811123/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f706163657269742f6c61726176656c2d636f72653f6c6162656c3d4c6963656e7365)](https://camo.githubusercontent.com/b38b06f44728065e3b432140d1a476bc2f2570d1d08fc655425ca4191e811123/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f706163657269742f6c61726176656c2d636f72653f6c6162656c3d4c6963656e7365)[![Packagist](https://camo.githubusercontent.com/ec651995ca5930b613a9b49a819fc4317c89bfdc4e74789b1854bf3f540244db/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f706163657269742f6c61726176656c2d636f72653f6c6162656c3d446f776e6c6f616473)](https://camo.githubusercontent.com/ec651995ca5930b613a9b49a819fc4317c89bfdc4e74789b1854bf3f540244db/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f706163657269742f6c61726176656c2d636f72653f6c6162656c3d446f776e6c6f616473)[![PHP from Packagist](https://camo.githubusercontent.com/5297ac59c41144de3f8a3f56c10256cfcc1c94e84cbdf05a71e929677016685d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f706163657269742f6c61726176656c2d636f72653f6c6162656c3d504850)](https://camo.githubusercontent.com/5297ac59c41144de3f8a3f56c10256cfcc1c94e84cbdf05a71e929677016685d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f706163657269742f6c61726176656c2d636f72653f6c6162656c3d504850)[![StyleCI](https://camo.githubusercontent.com/a32912752568bfc2fed1af246f46c816c73728628cdc20a4d0c7741b040eb87f/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3139393034353033382f736869656c643f6272616e63683d6d6173746572)](https://github.styleci.io/repos/199045038)[![Build Status](https://camo.githubusercontent.com/df14a14b5462d573e1074dfbe130783d53bc80f2ddf7a432dad2914f9889c989/68747470733a2f2f7472617669732d63692e636f6d2f706163657269742f6c61726176656c2d636f72652e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/pacerit/laravel-core)

Package of core classes that provide standardization in usage of Services, Repositories etc. for Laravel and Lumen framework.

Installation
------------

[](#installation)

You can install this package by composer:

```
composer require pacerit/laravel-core

```

### Version compatibility

[](#version-compatibility)

#### Laravel

[](#laravel)

FrameworkPackageNote5.8.x^1.x.xNo longer maintained.6.0.x^2.x.xBug fixes only.7.x.x^3.x.xBug fixes only.8.x.x^4.x.xPHP ^8.0 Supported from 4.0.49.x.x^5.x.x#### Lumen

[](#lumen)

FrameworkPackageNote5.8.x^1.1.xNo longer maintained.6.0.x^2.x.xBug fixes only.7.x.x^3.x.xBug fixes only.8.x.x^4.x.xPHP ^8.0 Supported from 4.0.49.x.x^5.x.xClasses included
----------------

[](#classes-included)

### Basic classes

[](#basic-classes)

```
CoreEntity::class - base class models
CoreRepository::class - base class of repositories (provided by package)
CoreService::class - base class of services
CoreFormatter::class - base class of formatter
CoreException::class - base class of exceptions

```

### Traits

[](#traits)

```
ScenatioTrait::class
StringTrait::class
NumberTrait::class
XMLTrait::class

```

Implementation
--------------

[](#implementation)

### Entities implementation

[](#entities-implementation)

In order to use Service, Repositories or Formatter classes, first you must prepare your entities. Every entity in you application must:

- Extend CoreEntity class
- Implements interface that extend CoreEntityInterface

For example, this is implementation of Example entity:

Example class:

```
class Example extends CoreEntity implements ExampleInterface
{}
```

ExampleInterface:

```
interface ExampleInterface extends CoreEntityInterface
{}
```

Interface and entity class must be bind in you app ServiceProvider:

```
/**
 * Register any application services.
 *
 * @return void
 */
public function register()
{
    $this->app->bind(ExampleInterface::class, Example::class);
}
```

#### Using UUID's in Entity

[](#using-uuids-in-entity)

**To use UUID feature install suggested ramsey/uuid package**

This package provides possibility to use UUID's in Entities as secondary key, for external use (i.e. in routes). It still requires to use integer type ID's as Primary keys in your database.

To use UUID's in your Entity, it must:

- Implements UUIDInterface
- Use UsesUUID trait

In your migration create field with "uuid" key using uuid() method.

```
$table->uuid(UsesUUID::UUID);
```

UUID's will bu automatically generated when new entity is created. If you use Services, you can add WithUUID trait to your implementation of CoreService class to add methods that are helpful when using UUID's.

```
class MyEntityService extends CoreService implements MyEntityServiceInterface
    use WithUUID;
    (...)
```

### Repositories implementation and usage

[](#repositories-implementation-and-usage)

Documentation of Repository can be found [here.](https://github.com/pacerit/laravel-repository)

### Services implementation

[](#services-implementation)

To use Service, create service class that:

- Extend CoreService class
- Implements interface that extend CoreServiceInterface

For example, this is implementation of service for Example entity:

ExampleServiceInterface:

```
interface ExampleServiceInterface extends CoreRepositoryInterface
{}
```

ExampleService class. In \_\_construct() function of class, provide class of repository for entity, and set it by setRepository() function. Optionally you can pass formatter for entity and set if by setFormattter() function to provide formatting functionality. Provided classes must be implementation of CoreRepository/CoreFormatter.

```
class ExampleService extends CoreService implements ExampleServiceInterface
{
    /**
     * ExampleService constructor.
     *
     * @param ExampleRepositoryInterface $exampleRepository
     * @param ExampleFormatterInterface $exampleFormatter
     */
    public function __construct(
        ExampleRepositoryInterface $exampleRepository,
        ExampleFormatterInterface $exampleFormatter
    ) {
        $this->setRepository($exampleRepository)
            ->setFormatter($exampleFormatter);
    }

}
```

#### Using services

[](#using-services)

To use Service in controller or other class you can use dependency injection or Container. Below is sample code of using service in controller.

```
class ExampleController extends Controller {

    /**
     * @var ExampleServiceInterface $exampleService
     */
    protected $exampleService;

    public function __construct(ExampleServiceInterface $exampleService){
        $this->exampleService = $exampleService;
    }

    ....
}
```

#### Available methods

[](#available-methods)

- setRepository() - set repository to use in service. Passing object must be implementation of CoreRepositoryInterface
- getRepository() - return previously set repository class instance
- setFormatter() - set formatter class to use in service. Passing object must be implementation of CoreFormatterInterface
- getFormatter() - return previously set formatter class instance
- setModel() - set model you want to work on i.e. if you already have instance
- setModelByID() - set model by given id (integer). If model with given ID exist, it will be set, otherwise exception will by thrown
- setModelByKey() - set model by given key (column in table) and given value. Helpful when looking for record by column other than ID (i.e foreign key)
- setNewMode() - set new model class instance
- getModel() - get previously set model class instance
- format() - get previously set model class instance and pass it to formatter class. CoreFormatterInterface instance will be return. Example of use.

```
// Return Example entity record with ID 1 as an array.
return $this->exampleService->setModelByID(1)->format()->toArray();
```

- create() - create new entity record based on actually set model, of given parameters. Example:

```
For this example, we assume that Example entity class have setFirstValue() and setSecondValue() functions (setters)
and const. Both of this example, create the same records in database.

// Create based on previously set entity.
$this->exampleService
    ->setNewModel()
    ->getModel()
    ->setFirstValue(1)
    ->setSecondValue(2);

$this->exampleService->create();

// Create model based on parameters.
$this-exampleService->create(
    [
        ExampleInterface::FIRST_VALUE => 1,
        ExampleInterface::SECOND_VALUE => 2,
    ]
);
```

- update() - update model. Like in create method it base on previously set model or parameters, but we must set existing model record before. Otherwise exception will be thrown. Example:

```
// Update based on previously set entity.
$this->exampleService
    ->setModelByID(1)
    ->getModel()
    ->setFirstValue(2);

$this->exampleService->update();

// Update model based on parameters.
$this-exampleService->update(
    1,
    [
        ExampleInterface::FIRST_VALUE => 2,
    ]
);
```

- delete() - delete model. Like in update() method, this also required to set existing model before.

```
$this->exampleService->setModelByID(1)->delete();
```

Traits
------

[](#traits-1)

### ScenarioTrait

[](#scenariotrait)

ScenarioTrait contains very useful functions, if we want use different class, based by some key (i.e. "type" field in entity).

For example - we have abstract "PaymentService" class with not implemented "create()" method. We create two classes that extend this class and implement create() function - each class for different payment provider:

```
* DummyProviderPaymentService::class - for "DummyProvider"
* OtherDummyProviderPaymentService::class - for "OtherDummyProvider"

```

each of them implements the create() function a little differently.

Normally if we want call create() function in matching class we will be do it like this:

```
(...)
switch ($type) {
    case 'DummyProvider':
        $service = new DummyProviderPaymentService::class;
        break;

    case 'OtherDummyProvider':
        $service = new OtherDummyProviderService::class;
        break;

     default:
        // Dunno what to do..
}

$service->create();
(...)
```

But if this class have dependency injection, that is not possible. And is not very elegant.

Here comes help from ScenarioTrait. With this class, we can solve this problem, for example, in this way:

```
(...)
$this->registerScenario('DummyProvider', DummyProviderPaymentService::class);
$this->registerScenatio('OtherDummyProvider', OtherDummyProviderService::class);

$this->getScenatioInstance($type)->create();
(...)
```

That's it. And yes - we can pass only namespace of class (even with dependency injection) - new instance will be created while call getScenarioInstance() method. Of course you can pass exist instance of class (.i.e. from dependency injection) - it's up to you.

Changelog
---------

[](#changelog)

Go to the [Changelog](CHANGELOG.md) for a full change history of the package.

Testing
-------

[](#testing)

```
composer test

```

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

If you discover a security vulnerability within package, please send an e-mail to Wiktor Pacer via . All security vulnerabilities will be promptly addressed.

License
-------

[](#license)

This package is open-source software licensed under the [MIT license](https://opensource.org/licenses/MIT).

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity77

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~21 days

Recently: every ~110 days

Total

45

Last Release

1543d ago

Major Versions

2.2.1 → 3.0.02020-03-19

3.0.1 → 4.0.02020-09-09

2.2.2 → 4.0.32020-12-02

2.x-dev → 4.0.42020-12-09

4.0.4 → 5.0.02022-02-16

PHP version history (5 changes)1.0.0PHP ^7.1

2.0.0PHP ^7.2

4.0.0PHP ^7.3

4.0.4PHP ^7.3|^8.0

5.0.0PHP ^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/53344063?v=4)[Wiktor Pacer](/maintainers/WiktorPacer)[@WiktorPacer](https://github.com/WiktorPacer)

---

Top Contributors

[![WiktorPacer](https://avatars.githubusercontent.com/u/53344063?v=4)](https://github.com/WiktorPacer "WiktorPacer (108 commits)")

---

Tags

entityformatterlaravellaravel-frameworkphprepositoryservicestraitframeworklaravelhelperscorerepositorypaceritLaravel Core

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/pacerit-laravel-core/health.svg)

```
[![Health](https://phpackages.com/badges/pacerit-laravel-core/health.svg)](https://phpackages.com/packages/pacerit-laravel-core)
```

###  Alternatives

[laravel/passport

Laravel Passport provides OAuth2 server support to Laravel.

3.4k85.0M529](/packages/laravel-passport)[laravel/pennant

A simple, lightweight library for managing feature flags.

57311.1M53](/packages/laravel-pennant)[laravel/cashier

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.

2.5k25.9M106](/packages/laravel-cashier)[laravel/lumen-framework

The Laravel Lumen Framework.

1.5k26.2M708](/packages/laravel-lumen-framework)[rebing/graphql-laravel

Laravel wrapper for PHP GraphQL

2.2k7.1M26](/packages/rebing-graphql-laravel)[graham-campbell/markdown

Markdown Is A CommonMark Wrapper For Laravel

1.3k7.1M63](/packages/graham-campbell-markdown)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
