This commit is contained in:
Masroor Ehsan 2024-12-30 20:11:07 +06:00
parent 959f368515
commit 35543023ee
3 changed files with 60 additions and 0 deletions

View File

@ -0,0 +1,33 @@
<?php
namespace App\Http\Controllers;
use Throwable;
use function Sentry\captureException as gobble;
abstract class HashidControllerBase extends Controller
{
protected ?int $key = null;
protected ?string $hashid = null;
protected function decodeKeys(): void
{
$this->hashid = request('hashid');
$this->decodeHashid($this->hashid);
}
protected function decodeHashId(?string $hashid): void
{
if (! blank($hashid)) {
try {
$this->key = unhash_it($hashid);
} catch (Throwable $exc) {
gobble($exc);
}
}
abort_if($this->key === null, 404);
}
}

View File

@ -0,0 +1,12 @@
<?php
namespace App\Http\Controllers\Staff;
use App\Http\Controllers\Controller;
class StudiesController extends Controller
{
public function index() {}
public function series() {}
}

15
app/helpers.php Normal file
View File

@ -0,0 +1,15 @@
<?php
if (! function_exists('hash_it')) {
function hash_it(int $key): string
{
return Hashids::encode($key);
}
}
if (! function_exists('unhash_it')) {
function unhash_it(string $hashid): int
{
return (int) Hashids::decode($hashid)[0];
}
}