定制 mpyw/laravel-unique-violation-detector 二次开发

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

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

mpyw/laravel-unique-violation-detector

最新稳定版本:v1.1.3

Composer 安装命令:

composer require mpyw/laravel-unique-violation-detector

包简介

Detect primary/unique key or constraint violation errors from PDOException.

README 文档

README

Caution

ABANDONED: The functionalities of this library have been integrated into the Laravel core due to changes in Laravel v10.20.0. From now on, the Illuminate\Database\UniqueConstraintViolationException exception class will be thrown when there is a unique constraint violation, so there is no need to use this library for judgment. Simply checking with catch or instanceof should be sufficient. Although the internal judgment logic is strictly different in some parts, it should be replaceable without any problems in most cases.

Detect primary/unique key or constraint violation errors from PDOException.

Requirements

Package Version
PHP ^8.0
Laravel ^9.0 || ^10.0
mpyw/unique-violation-detector ^1.0

Supported Connections

Database Connection Class
MySQL Illuminate\Database\MySqlConnection
PostgreSQL Illuminate\Database\PostgresConnection
SQLite Illuminate\Database\SQLiteConnection
SQLServer Illuminate\Database\SqlServerConnection

You can also add custom resolvers by one of the following:

  • Mpyw\LaravelUniqueViolationDetector\Facades\Unique::resolverFor()
  • Mpyw\LaravelUniqueViolationDetector\DetectorDiscoverer::resolverFor()

Installing

composer require mpyw/laravel-unique-violation-detector

Usage

You can detect unique violations in various ways.

use Mpyw\LaravelUniqueViolationDetector\UniqueViolationDetector;
use Mpyw\LaravelUniqueViolationDetector\Facades\Unique;

// Detect on a specific connection via explicitly created detector instance
// (Recommended usage in libraries)
$violated = (new UniqueViolationDetector($connection))->violated($e);

// Detect on the default connection
$violated = Unique::violated($exception);

// Detect on a specific connection via Facade
$violated = Unique::forConnection($connection)->violated($e);

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-11-26