PHPackages                             effectra/laravel-model-operations - 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. [Database &amp; ORM](/categories/database)
4. /
5. effectra/laravel-model-operations

ActiveLibrary[Database &amp; ORM](/categories/database)

effectra/laravel-model-operations
=================================

A Laravel package for model operations.

v1.0.2(9mo ago)12MITPHPPHP &gt;=8.1

Since Aug 28Pushed 9mo agoCompare

[ Source](https://github.com/effectra/laravel-model-operations)[ Packagist](https://packagist.org/packages/effectra/laravel-model-operations)[ RSS](/packages/effectra-laravel-model-operations/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (3)Dependencies (5)Versions (4)Used By (0)

LaravelModelOperations
======================

[](#laravelmodeloperations)

`LaravelModelOperations` is a lightweight package that provides reusable **traits** for performing common Eloquent model operations in Laravel, such as creating, updating, deleting, and handling bulk actions.

It helps keep your controllers and services clean by centralizing repetitive model logic into reusable traits.

---

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

[](#installation)

You can install the package via Composer:

```
composer require effectra/laravel-model-operations
```

---

Features
--------

[](#features)

- 🎯 Simplified model operations (`create`, `createMany`, etc.)
- 🔄 Bulk operations with error handling
- 🛡️ Strong typing &amp; exceptions for better safety
- 🧩 Easy to extend with your own logic

---

The `UseCreate` Trait
---------------------

[](#the-usecreate-trait)

The `UseCreate` trait provides methods to **create single or multiple model records** in a clean and reusable way.

### Importing the trait

[](#importing-the-trait)

```
use LaravelModelOperations\Traits\UseCreate;

class UserService
{
    use UseCreate;

    protected string $model = \App\Models\User::class;
}
```

---

### Creating a single record

[](#creating-a-single-record)

```
// In a controller or service:
$userService = new UserService();

// Example request validation
$request = new \Illuminate\Http\Request([
    'name' => 'John Doe',
    'email' => 'john@example.com',
    'password' => bcrypt('secret'),
]);

// Create user
$created = $userService->create($request);

if ($created) {
    $user = $userService->getModelCreated();
    dump("User created:", $user->toArray());
}
```

✅ **What happens here?**

- The data is validated (`$request->validated()`) before being used.
- A new `User` is created and stored in `$userService->getModelCreated()`.
- If creation fails, it simply returns `false`.

---

### Creating with default attributes

[](#creating-with-default-attributes)

Sometimes you want to **add default values** during creation:

```
$created = $userService->create(
    $request,
    ['status' => 'active'] // default values
);
```

This will merge defaults with the validated request before saving.

---

### Adding a callback after creation

[](#adding-a-callback-after-creation)

You can pass a closure that runs after successful save:

```
$created = $userService->create($request, [], function ($user) {
    // Send a welcome email
    \Mail::to($user->email)->send(new \App\Mail\WelcomeMail($user));
});
```

---

### Creating multiple records at once

[](#creating-multiple-records-at-once)

```
$request = new \Illuminate\Http\Request([
    [
        'name' => 'User 1',
        'email' => 'user1@example.com',
        'password' => bcrypt('secret'),
    ],
    [
        'name' => 'User 2',
        'email' => 'user2@example.com',
        'password' => bcrypt('secret'),
    ]
]);

$success = $userService->createMany($request);

if ($success) {
    echo "All users created successfully!";
} else {
    echo "Some users failed to create. Failed index: " . $userService->modelFailedIndex;
}
```

✅ **What happens here?**

- Each item in the request array is passed to `create()`.
- If all succeed → returns `true`.
- If one fails → returns `false` and stores the **failed index** for debugging.

---

Exception Handling
------------------

[](#exception-handling)

When bulk creation fails, a `ManyOperationException` can be thrown with the index of the failed item.

```
try {
    $success = $userService->createMany($request);
} catch (\ManyOperationException $e) {
    logger("Failed at index: " . $e->getIndex());
}
```

---

License
-------

[](#license)

This package is open-sourced under the [MIT license](LICENSE).

---

###  Health Score

30

—

LowBetter than 61% of packages

Maintenance55

Moderate activity, may be stable

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 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 ~28 days

Total

3

Last Release

298d ago

PHP version history (2 changes)v1.0.0PHP ^8.0

v1.0.2PHP &gt;=8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/7e6219ae87e98df8783b2f595b013035dd183c0712afd24045a8acf0a40c3bdf?d=identicon)[effectra](/maintainers/effectra)

---

Top Contributors

[![BMTmohammedtaha](https://avatars.githubusercontent.com/u/95439605?v=4)](https://github.com/BMTmohammedtaha "BMTmohammedtaha (10 commits)")

###  Code Quality

TestsPest

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/effectra-laravel-model-operations/health.svg)

```
[![Health](https://phpackages.com/badges/effectra-laravel-model-operations/health.svg)](https://phpackages.com/packages/effectra-laravel-model-operations)
```

###  Alternatives

[spatie/laravel-medialibrary

Associate files with Eloquent models

6.2k45.4M704](/packages/spatie-laravel-medialibrary)[spatie/laravel-health

Monitor the health of a Laravel application

88212.7M188](/packages/spatie-laravel-health)[psalm/plugin-laravel

Psalm plugin for Laravel

3345.4M354](/packages/psalm-plugin-laravel)[yajra/laravel-oci8

Oracle DB driver for Laravel via OCI8

8723.3M27](/packages/yajra-laravel-oci8)[simplestats-io/laravel-client

Server-side analytics for Laravel that follows the full funnel from visit to registration to payment, attributed to the channel that drove it. Revenue, MRR, churn and ad-spend profit (ROAS/CAC) per channel. GDPR compliant, ad-blocker proof.

5226.7k](/packages/simplestats-io-laravel-client)[masterix21/laravel-licensing

Laravel licensing package with polymorphic assignment to any model, activation keys, expirations/renewals, and seat control via LicenseUsage. Supports offline verification with public-key–signed tokens, a CLI to generate/rotate/revoke keys, and an extensible architecture via config and contracts.

1614.1k4](/packages/masterix21-laravel-licensing)

PHPackages © 2026

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