Merge remote-tracking branch 'origin/master' into mhmfajar

This commit is contained in:
Muhammad Fajar
2022-11-03 05:12:56 +07:00
5 changed files with 85 additions and 12 deletions

View File

@@ -20,6 +20,10 @@ class File extends Model
'path',
];
public $appends = [
'url'
];
public static $file_directories = [
'import-temp' => 'import-temp/',
'avatar' => 'user-avatar/',
@@ -41,6 +45,11 @@ class File extends Model
return $type . '-' . $id . '-' . Str::random(10);
}
public function getUrlAttribute()
{
return url($this->path);
}
public static function storeFile($type, $id, $file)
{
$fileName = self::getFileName($type, $id);

View File

@@ -88,8 +88,18 @@ class Person extends Model
return $this->morphOne(File::class, 'fileable')->where('type', 'avatar')->latestOfMany();
}
public function families()
{
return $this->belongsToMany(Person::class, 'family_relations', 'owner_id', 'person_id')->withPivot(['relation_with_owner']);
}
public function familyOwner()
{
return $this->hasOne(Family::class, 'person_id');
}
public function user()
{
return $this->hasOne(User::class, 'person_id');
}
}

View File

@@ -47,6 +47,10 @@ class User extends Authenticatable
'otp_created_at' => 'datetime'
];
public $with = [
'metas'
];
public $appends = [
'meta'
];