PHPackages                             major-phyo-san/prevent-same-shit - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. major-phyo-san/prevent-same-shit

ActiveLibrary[Database &amp; ORM](/categories/database)

major-phyo-san/prevent-same-shit
================================

"Prevent duplicate database records by calculating SHA256 hash for each database entry"

0.0.18(11mo ago)029MITPHPPHP ^8.1

Since Apr 30Pushed 11mo ago1 watchersCompare

[ Source](https://github.com/major-phyo-san/prevent-same-shit)[ Packagist](https://packagist.org/packages/major-phyo-san/prevent-same-shit)[ RSS](/packages/major-phyo-san-prevent-same-shit/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (4)Versions (19)Used By (0)

Prevent Same Shit
=================

[](#prevent-same-shit)

[![Latest Version on Packagist](https://camo.githubusercontent.com/5ee7f6833b33f19301a1a3f3d74ed29a2975445508034aa6ed785938bf47bfe9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d616a6f722d7068796f2d73616e2f70726576656e742d73616d652d736869742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/major-phyo-san/prevent-same-shit)[![Total Downloads](https://camo.githubusercontent.com/f237d4cb71c4082b96720666e68c903b6aa0d82d55c9eff8810fd0f9af93523a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d616a6f722d7068796f2d73616e2f70726576656e742d73616d652d736869742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/major-phyo-san/prevent-same-shit)[![License](https://camo.githubusercontent.com/0c1ac9caa2bee66fd66ef3d1a3747f0670336a048523d1add50f4360f81df53e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6d616a6f722d7068796f2d73616e2f70726576656e742d73616d652d736869742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/major-phyo-san/prevent-same-shit)

Introduction
------------

[](#introduction)

`Prevent Same Shit` is a Laravel package (based on Laravel 10) that provides a simple and efficient way to prevent duplicate database records. It helps developers handling of duplications of each record at database level, making their work easier and more efficient.

---

What It Does
------------

[](#what-it-does)

This package generates `'record_hash'` (or if you prefer, your custom `hash_column_name`) database columns for Eloquent models. The `'record_hash'` column stores SHA256 hash for each database entry of a specific models. When there's a new record entry, the package will calculate the hash value of the new record, checking it against the existing hash values and if any duplication exists, prevent the entry of the new record.

Installation
------------

[](#installation)

You can install the package via Composer:

```
composer require major-phyo-san/prevent-same-shit
```

Laravel uses Package Auto-Discovery, so doesn't require you to manually add the ServiceProvider. But for the standard documentation purpose, the following is the package discovery.

```
php artisan vendor:publish --provider="MajorPhyoSan\\PreventSameShit\\PreventSameShitServiceProvider"
```

Usage
-----

[](#usage)

The `HasRowHash` trait will handle record hashing and checking if duplicated record exists based on the hash value automatically. All you need to do is to use the trait in your Eloquent model. The model using the trait must have the `'record_hash'` \[string, nullable\] (or your custom hash column name, just don't forget to provide your custom hash column name in the model) column.

### Example

[](#example)

```
