peltonsolutions/laravel-pivot-table-helper 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

peltonsolutions/laravel-pivot-table-helper

最新稳定版本:0.2.0

Composer 安装命令:

composer require peltonsolutions/laravel-pivot-table-helper

包简介

A custom package for Laravel to assist with creating BelongsToMany pivot migrations.

README 文档

README

Description WIP

Things to add

  • allow nullable relationships, when you have multiple
  • add morphToMany
  • add command to automatically create the migration file from a model/relationship
  • If the target table already exists, update the table instead
  • Add "down" generation, which determines if the target table only has the two column relationship or not. If it only has these two fields, it will drop the table. If it has more fields, it will remove the column for the relationship column.

Install

You can install the package via composer using the following command:

composer require peltonsolutions/laravel-pivot-table-helper

Usage

<?php

use App\Models\User;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\Schema;
use PeltonSolutions\LaravelPivotTableHelper\Models\GenerateBelongsToManyMigration;

return new class extends Migration {
	/**
	 * Run the migrations.
	 */
	public function up(): void
	{
		GenerateBelongsToManyMigration::createMigration(
			(new User())->roles()
		);
	}

	/**
	 * Reverse the migrations.
	 */
	public function down(): void
	{
		Schema::dropIfExists((new User())->roles()->getTable());
	}
};

Or, you can pass an array of relationships. This assumes it's sharing the same pivot table, and the same parent class

<?php

use App\Models\User;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\Schema;
use PeltonSolutions\LaravelPivotTableHelper\Models\GenerateBelongsToManyMigration;

return new class extends Migration {
	/**
	 * Run the migrations.
	 */
	public function up(): void
	{
	    $instance = new User();
		GenerateBelongsToManyMigration::createMigration([
			$instance->relationship1(),
			$instance->relationship2(),
		]);
	}

	/**
	 * Reverse the migrations.
	 */
	public function down(): void
	{
		Schema::dropIfExists((new User())->roles()->getTable());
	}
};

Security

If you discover any security-related issues, please email security@peltonsolutions.com instead of using the issue tracker.

Credits

License

laravel-pivot-table-helper is open-sourced software. It's licensed under the MIT license, which is a permissive license allowing the software to be used, modified, and shared.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-02-10

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固