定制 patrickcurl/laravel-computed-columns 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

patrickcurl/laravel-computed-columns

Composer 安装命令:

composer require patrickcurl/laravel-computed-columns

包简介

Adds the methods: md5AsComputed, jsonFieldStoredAs, manyJsonFieldsStoredAs, concatWsStoredAs.

README 文档

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

This package is an extension to laravel migrations to add some more optimized virtual/storedAs fields based on common use cases (at least my own);

Support us

Installation

You can install the package via composer:

composer require patrickcurl/laravel-computed-columns

You can publish and run the migrations with:

Usage

I'm planning on better documentation but the simplest way to jump in is look at some code.

<?php

declare(strict_types=1);

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Migrations\Migration;

return new class() extends Migration {
    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('locations');
        Schema::dropIfExists('locateables');
    }

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('locations', function (Blueprint $table) {
            $table->id();
            $table->json('data')->nullable();

            $table->computedJsonColumns( // notice the plurality of columns.
                'stored' // the type, accepts: 'stored' and 'virtual'
                'data', // the json column to extract data from.
                [ // The fields in the data json object to convert to computed fields.
                    'type',
                    'country',
                    'country_code',
                    'state',
                    'postcode',
                    'city',
                    'lat',
                    'lng',
                ], // loop over these fields and run the storedAs method see example below.
                true // should each field be nullable?
            );

            // This is the equivalent of running:
            // $field = 'data->';
            // $path = 'country';
            // $this->string('type')->storedAs('json_unquote(json_extract('.$field.$path.'))');


            // concatWsStoredAs($column, $default, $separator, ...$fields)
            $table->computedConcatWsColumn(
                'stored' // type
                'label', // computed column name
                'data->label', // json path default value if other sources come up null.
                ', ', // separator
                'city', // ...$fields|$fields[] which fields on data to convert from:
                'state', // e.g. state will give you $model->state === $model->data->state;
                'country',
                'postcode'
            ); // This will use the default if it exists, otherwise it'll create a default either from json nested keys where fields are ['data->city', 'data->state', etc....];

            // This one simply creates an id, my location example basically does a lookup of data via openstreetmaps, and caches the label, and then if someone adds that to their profile as their location it'll pull it all in at that point either from the api, or the cache, or an existing location as we're only dealing with city/state not actual full addresses.

            // This isn't the most secure thing, for an id that's not critical that it's secret this is fine, but I wouldn't use it to hash passwords!
            $table->computedMd5Column(
                'stored', // type
                'uid', // column
                'label' // label column will be used, could also use data->label to use the original json to map from.
            );

            // alternately I could've used :
            $table->computedWrappedColumn(
                'stored',
                'MD5',
                'uid',
                'label'
            ) ;

            $table->timestamps();
        });

        Schema::create('locateables', function (Blueprint $table) {
            $table->id();
            $table->foreignId('location_id')->constrained();
            $table->morphs('locateable');
            $table->unique(['location_id', 'locateable_id', 'locateable_type']);
        });
    }
};

## Testing

```bash
composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

patrickcurl/laravel-computed-columns 适用场景与选型建议

patrickcurl/laravel-computed-columns 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 25 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 10 月 01 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「patrickcurl」 「laravel-computed-columns」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 patrickcurl/laravel-computed-columns 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 patrickcurl/laravel-computed-columns 我们能提供哪些服务?
定制开发 / 二次开发

基于 patrickcurl/laravel-computed-columns 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 25
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 30
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-10-01