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(6mo ago)12MITPHPPHP &gt;=8.1

Since Aug 28Pushed 6mo 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 1mo 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

33

—

LowBetter than 74% of packages

Maintenance70

Regular maintenance activity

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity46

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

197d 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

[dyrynda/laravel-model-uuid

This package allows you to easily work with UUIDs in your Laravel models.

4802.8M8](/packages/dyrynda-laravel-model-uuid)[clickbar/laravel-magellan

This package provides functionality for working with the postgis extension in Laravel.

423715.4k1](/packages/clickbar-laravel-magellan)[cybercog/laravel-love

Make Laravel Eloquent models reactable with any type of emotions in a minutes!

1.2k302.7k1](/packages/cybercog-laravel-love)[cviebrock/eloquent-taggable

Easy ability to tag your Eloquent models in Laravel.

567694.8k3](/packages/cviebrock-eloquent-taggable)[genealabs/laravel-pivot-events

This package introduces new eloquent events for sync(), attach(), detach() or updateExistingPivot() methods on BelongsToMany relation.

1404.9M8](/packages/genealabs-laravel-pivot-events)[jerome/filterable

Streamline dynamic Eloquent query filtering with seamless API request integration and advanced caching strategies.

19226.1k](/packages/jerome-filterable)

PHPackages © 2026

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