add Hash
Tests & Lint & Deploy to Railway / build (2.6.6, 20.x, 8.3) (push) Failing after 54s Details
Tests & Lint & Deploy to Railway / deploy (push) Has been skipped Details

This commit is contained in:
aslan 2024-07-12 12:48:28 +03:00
parent 2d9ca7a95c
commit 540734aaed
3 changed files with 78 additions and 0 deletions

View File

@ -0,0 +1,29 @@
<?php
namespace App\Helpers;
use App\Models\User;
class HashHelper
{
protected const string algo = 'sha256';
public static function getRecordHash(User $user): string
{
$fields = AllfieldsUserHelper::get();
$data = array_map(fn ($item) => $user->$item, $fields);
$dataInLine = implode($data);
// dd($data);
return hash(self::algo, $dataInLine);
}
public static function getApiHash($infoOfStudent): string
{
// dd($infoOfStudent);
$fields = AllfieldsUserHelper::get();
$data = array_map(fn ($item) => $infoOfStudent[$item], $fields);
// dd($data);
$dataInLine = implode($data);
// dd($dataInLine);
return hash(self::algo, $dataInLine);
}
}

20
app/Models/HashRecord.php Normal file
View File

@ -0,0 +1,20 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class HashRecord extends Model
{
protected $fillable = [
'id',
'user_id',
'hash',
];
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
}

View File

@ -0,0 +1,29 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('hash_records', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->constrained('users');
$table->string('hash', 255)->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('hash_records');
}
};