A simple library for formatting the duplicate message in MySQL
- PHP >= 7
$ composer test
$ composer cs
$ composer csfix
<?php
use \MySQLUniqueMessage\UniqueMessage;
// This message will return in your mysql using try / catch block
$message = 'SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry \'[email protected]\' for key \'email\'';
$output = UniqueMessage::format($message);
Dump from $output
[
'name' => 'email',
'value' => '[email protected]',
'message' => 'The email \'[email protected]\' is already registered.'
];
Enjoy!