Closed singleseeker closed 2 years ago
When we get entity attributes, it will check if it is a valid entity.
public function getEntityAttributes(): Collection
{
$morphClass = $this->getMorphClass();
static::$entityAttributes = static::$entityAttributes ?? collect();
if (! static::$entityAttributes->has($morphClass) && Schema::hasTable(config('rinvex.attributes.tables.attribute_entity'))) {
$locale = app()->getLocale();
/* This is a trial to implement per resource attributes,
it's working but I don't like current implementation.
$routeParam = request()->route($morphClass);
// @TODO: This is REALLY REALLY BAD DESIGN!! But can't figure out a better way for now!!
// Refactor required, we need to catch `$this` itself, we should NOT use request and routes here!!
// But still at this very early stage, `$this` still not bound to model's data, so it's just empty object!
$entityId = $routeParam && collect(class_uses_recursive(static::class))->contains(HashidsTrait::class) && ! is_numeric($routeParam)
? optional(Hashids::decode($routeParam))[0] : $routeParam;
$attributes = app('rinvex.attributes.attribute_entity')->where('entity_type', $morphClass)->where('entity_id', $entityId)->get()->pluck('attribute_id');
*/
$attributes = app('rinvex.attributes.attribute_entity')->where('entity_type', $morphClass)->get()->pluck('attribute_id');
static::$entityAttributes->put($morphClass, app('rinvex.attributes.attribute')->whereIn('id', $attributes)->orderBy('sort_order', 'ASC')->orderBy("name->\${$locale}", 'ASC')->get()->keyBy('slug'));
}
return static::$entityAttributes->get($morphClass) ?? new Collection();
}
So what's the question exactly?! 🤔
According to the following document, we need to register our entities.I have no idea why we are doing this.
I found that even the model does not exist, also we could insert the record.
For example, I don't have
App\Models\Company
, but with the following code, I still can get a record of the company.