PHPackages                             liaosp/laravel-relation-save - 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. liaosp/laravel-relation-save

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

liaosp/laravel-relation-save
============================

laravel 关联保存 hasOne hasMany belongsto

v1.0.6(3y ago)4181MITPHP

Since Sep 8Pushed 3y ago1 watchersCompare

[ Source](https://github.com/liaoshengping/laravel-relation-save)[ Packagist](https://packagist.org/packages/liaosp/laravel-relation-save)[ RSS](/packages/liaosp-laravel-relation-save/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (8)Used By (0)

 laravel-relation-save
=======================

[](#-laravel-relation-save-)

 📦laravel 关联保存 hasOne hasMany belongsto.

[![Latest Stable Version](https://camo.githubusercontent.com/e3a6e88021c6097a19d11a2f918dc19c135ff968b1b21a1d868cc205698a430c/68747470733a2f2f706f7365722e707567782e6f72672f6c69616f73702f6c61726176656c2d72656c6174696f6e2d736176652f762f737461626c65)](https://packagist.org/packages/liaosp/laravel-validate-ext)[![Total Downloads](https://camo.githubusercontent.com/708ccb90c67a662deda31b0a88fd27127fa8d0dedce01fcb5184789453e85ee5/68747470733a2f2f706f7365722e707567782e6f72672f6c69616f73702f6c61726176656c2d72656c6174696f6e2d736176652f646f776e6c6f616473)](https://packagist.org/packages/liaosp/laravel-validate-ext)[![Daily Downloads](https://camo.githubusercontent.com/18a7bff774dd554babc742160ac9ae12553ccf0e311294f841fcc6a5bd536015/68747470733a2f2f706f7365722e707567782e6f72672f6c69616f73702f6c61726176656c2d72656c6174696f6e2d736176652f642f6461696c79)](https://packagist.org/packages/liaosp/laravel-validate-ext)[![License](https://camo.githubusercontent.com/aaa7fe792f567a9ab43d978b2075fa9b09efa80803832bceb2470ff7196c38ac/68747470733a2f2f706f7365722e707567782e6f72672f6c69616f73702f6c61726176656c2d72656c6174696f6e2d736176652f6c6963656e7365)](https://packagist.org/packages/liaosp/laravel-validate-ext)[![StyleCI](https://camo.githubusercontent.com/80453dbca2e64b853d5f4ac532214958140de4b89e17f0acebbaa29337c6443b/68747470733a2f2f7374796c6563692e696f2f7265706f732f35333136333430352f736869656c64)](https://styleci.io/repos/53163405/)

github
------

[](#github)

Installing
----------

[](#installing)

```
$ composer require liaosp/laravel-relation-save -vvv
```

✈Usage
------

[](#usage)

在模型中添加

```
use SaveRelation;

```

🔨使用

```
$this->model->save($validate->getData());

$this->model->saveRelation($validate->getData());

```

🌰 example
---------

[](#-example)

比如有主表shop 和 store\_detail

定义HasOne 关系

```
   public function store_detail()
    {
        return $this->hasOne(\App\Models\StoreDetail::class, 'store_id', 'id');
    }

```

比如前端json 请求

```
  {
    "name": "老廖的店铺",
    "store_detail": {
      "address": "福建省厦门市思明区吕厝地铁口"
    }
  }

```

创建数据简化前 （大概是这种意思）

```
 //一些店铺操作
 $this->store->save();
 $this->store_detail->store_id = $this->store->id;
 $this->store_detail->address = $request->get('store_detail')['address'];
 $this->store_detail->save();

```

我看了下Laravel-admin 的关联保存，对于快速开发的项目，觉得挺好的，值得学习。`encore\laravel-admin\src\Form.php`

只需如下可以保存关联关系的数据了

```
$this->model->save($request->all());

$this->model->saveRelation($request->all());

```

更新日志
----

[](#更新日志)

```
2022年3月27日10:21:21  多对多无限级保存

```

适用 创建和更新 ，可参考源码，学习更多小技巧。

[laravel-relation-save](https://github.com/liaoshengping/laravel-relation-save)

✏Reference
----------

[](#reference)

[laravel-admin](https://laravel-admin.org/)

[【源码分析】Laravel-admin 关联保存的原理](https://blog.csdn.net/qq_22823581/article/details/120101938)

Other
-----

[](#other)

[Laravel 验证中文扩展](https://github.com/liaoshengping/laravel-validate-ext)

Contributing
------------

[](#contributing)

You can contribute in one of three ways:

1. File bug reports using the [issue tracker](https://github.com/liaosp/laravel-relation-save/issues).
2. Answer questions or fix bugs on the [issue tracker](https://github.com/liaosp/laravel-relation-save/issues).
3. Contribute new features or update the wiki.

*The code contribution process is not very formal. You just need to make sure that you follow the PSR-0, PSR-1, and PSR-2 coding guidelines. Any new code contributions must be accompanied by unit tests where applicable.*

License
-------

[](#license)

MIT

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity55

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

Recently: every ~71 days

Total

7

Last Release

1414d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/440eb424aa6385a9bca5bf1597270a4235e943a67536900f7fbf0c8cdb96594e?d=identicon)[liaoshengping](/maintainers/liaoshengping)

---

Top Contributors

[![liaoshengping](https://avatars.githubusercontent.com/u/24541157?v=4)](https://github.com/liaoshengping "liaoshengping (12 commits)")

### Embed Badge

![Health badge](/badges/liaosp-laravel-relation-save/health.svg)

```
[![Health](https://phpackages.com/badges/liaosp-laravel-relation-save/health.svg)](https://phpackages.com/packages/liaosp-laravel-relation-save)
```

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[mongodb/mongodb

MongoDB driver library

1.6k64.0M546](/packages/mongodb-mongodb)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90340.3M211](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)

PHPackages © 2026

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