wip
This commit is contained in:
parent
959f368515
commit
35543023ee
33
app/Http/Controllers/HashidControllerBase.php
Normal file
33
app/Http/Controllers/HashidControllerBase.php
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
12
app/Http/Controllers/Staff/StudiesController.php
Normal file
12
app/Http/Controllers/Staff/StudiesController.php
Normal 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
15
app/helpers.php
Normal 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];
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user