use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Schema\Table;
use Illuminate\Database\Eloquent\Model;
+use Illuminate\Support\Facades\App;
use Illuminate\Support\Str;
use Spatie\MediaLibrary\HasMedia\HasMedia;
use Spatie\MediaLibrary\HasMedia\HasMediaTrait;
*
* @return array
*/
- public function sluggable():array
+ public function sluggable(): array
{
return [
'slug' => [
$slug = [];
foreach ($components as $component) {
- if (isset($this->$component) && $this->$component != '') {
- $slug[] = $this->$component;
+ $v = $this->getAttribute($component);
+
+ if ($v) {
+ $slug[] = $v;
}
}
if (count($slug) > 0) {
return $field;
}
+ public function getTranslations(string $key = null): array
+ {
+ if ($key !== null) {
+ $this->guardAgainstNonTranslatableAttribute($key);
+
+ if ($key === 'slug') {
+ return array_filter(json_decode($this->getAttributes()[$key] ?? '' ?: '{}', true) ?: [], function ($value) {
+ return $value !== null;
+ });
+ } else {
+ return array_filter(json_decode($this->getAttributes()[$key] ?? '' ?: '{}', true) ?: [], function ($value) {
+ return $value !== null && $value !== '';
+ });
+ }
+ }
+
+ return array_reduce($this->getTranslatableAttributes(), function ($result, $item) {
+ $result[$item] = $this->getTranslations($item);
+
+ return $result;
+ });
+ }
+
public function update(array $attributes = [], array $options = [])
{
return $this->updateTranslations($this->_prepareData($attributes), $options);