value ?? null; } /** * @return mixed|null */ public function getImageAttribute(): mixed { return $this->files()->first() ?? null; } /** * @return BelongsTo */ public function variation(): BelongsTo { return $this->belongsTo(Variation::class); } protected function extractMediaFromRequest() { if (request()->routeIs('admin.variations.*')) { return $this->extractMediaForGlobal(); } if (request()->routeIs('admin.products.*')) { return $this->extractMediaForLocal(); } } protected function extractMediaForGlobal() { if (request('type') === 'image') { return [ 'media' => [request('values.' . $this->uid . '.image')], ]; } } protected function extractMediaForLocal() { if ($this->variation->type === 'image') { return [ 'media' => [request('variations.' . $this->variation->uid . '.values.' . $this->uid . '.image')], ]; } } }