add Hash
This commit is contained in:
parent
2d9ca7a95c
commit
540734aaed
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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');
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue