Add PropController, StorePropRequest, UpdatePropRequest, PropResource, and PropableModels; define API routes for props management
This commit is contained in:
42
app/Domains/Prop/Support/PropableModels.php
Normal file
42
app/Domains/Prop/Support/PropableModels.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Prop\Support;
|
||||
|
||||
use App\Domains\Product\Models\Brand;
|
||||
use App\Domains\Product\Models\Category;
|
||||
use App\Domains\Product\Models\Product;
|
||||
use App\Domains\Prop\Concerns\Propable;
|
||||
use App\Domains\Tenant\Models\Tenant;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Arr;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
class PropableModels
|
||||
{
|
||||
/**
|
||||
* @return array<string, class-string<Model>>
|
||||
*/
|
||||
public static function map(): array
|
||||
{
|
||||
return [
|
||||
'brand' => Brand::class,
|
||||
'category' => Category::class,
|
||||
'product' => Product::class,
|
||||
'tenant' => Tenant::class,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return class-string<Model>
|
||||
*/
|
||||
public static function resolveOrFail(string $alias): string
|
||||
{
|
||||
$modelClass = Arr::get(static::map(), $alias);
|
||||
|
||||
if (! is_string($modelClass) || ! is_subclass_of($modelClass, Model::class) || ! in_array(Propable::class, class_uses_recursive($modelClass), true)) {
|
||||
throw new NotFoundHttpException('Propable model not found.');
|
||||
}
|
||||
|
||||
return $modelClass;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user