initial: bootstrap from BukidBountyApp base
This commit is contained in:
42
app/Http/Controllers/Helpers/QueryHelper.php
Normal file
42
app/Http/Controllers/Helpers/QueryHelper.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers\Helpers;
|
||||
|
||||
|
||||
use App\Models\FileList;
|
||||
use Hypervel\Http\Request;
|
||||
use App\Http\Controllers\FilesMainController;
|
||||
use Hypervel\Database\Eloquent\Model;
|
||||
|
||||
class QueryHelper
|
||||
{
|
||||
|
||||
public static function findOrNullByHashOrId(
|
||||
int|string|Model|false $hashOrId,
|
||||
string $modelClass
|
||||
): false|Model {
|
||||
|
||||
if (!$hashOrId) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if ($hashOrId instanceof Model) {
|
||||
return $hashOrId;
|
||||
}
|
||||
|
||||
|
||||
if (!is_subclass_of($modelClass, Model::class)) {
|
||||
throw new \InvalidArgumentException('Invalid model class');
|
||||
}
|
||||
|
||||
if (is_int($hashOrId)) {
|
||||
return $modelClass::find($hashOrId);
|
||||
}
|
||||
|
||||
return $modelClass::where('hashkey', $hashOrId)->first();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user