承接 hulkur/laravel-hasmany-keyby 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

hulkur/laravel-hasmany-keyby

最新稳定版本:8.0

Composer 安装命令:

composer require hulkur/laravel-hasmany-keyby

包简介

Add possibility to have related models in many-to-many relationship attached to the parent model by defined key values.

README 文档

README

Latest Version on Packagist GitHub Workflow Status Total Downloads

Adds possibility to have related models in many-to-many relationship attached to the parent model by defined key values. Usually it would be related model id.

call:

$users = User::with('groups')->all()

laravel default:

$user->groups = [0 => $group];

New usage with keyBy:

class User extends Model
{
  use HasManyKeyByRelationship;

  public function groups()
  {
    return $this->hasMany(Group::class)->keyBy('id'); // can be string or callable
  }
}

result:

$user->groups = [$group->id => $group];

Some real life use cases

  1. When you need to target order items by product id to apply order discounts.

    • Ex: discount for specific product on order total/shipping method etc
  2. When you need to manipulate pivot records in mass.

    • Ex: users/groups grid where grid fields are some value in pivot record and not all pivot records exist
@foreach($users as $user)
  @foreach($groups as $group)
    {{$user->accesslevels[$group->id]?->level}}
  @endforeach
@endforeach

统计信息

  • 总下载量: 81.39k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 未知

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固