api person create & update & add family
This commit is contained in:
@@ -10,7 +10,7 @@ use Illuminate\Support\Str;
|
||||
class File extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
|
||||
protected $fillable = [
|
||||
'fileable_type',
|
||||
'fileable_id',
|
||||
@@ -20,12 +20,10 @@ class File extends Model
|
||||
'path',
|
||||
];
|
||||
|
||||
protected $appends = [
|
||||
'url'
|
||||
];
|
||||
|
||||
public static $file_directories = [
|
||||
'import-temp' => 'import-temp/',
|
||||
'avatar' => 'user-avatar/',
|
||||
'dataDiri' => 'data-diri/'
|
||||
];
|
||||
|
||||
public function fileable()
|
||||
@@ -33,29 +31,23 @@ class File extends Model
|
||||
return $this->morphTo();
|
||||
}
|
||||
|
||||
public function getUrlAttribute()
|
||||
{
|
||||
return Storage::url($this->path);
|
||||
}
|
||||
|
||||
public function getDirectory($type)
|
||||
public static function getDirectory($type)
|
||||
{
|
||||
return self::$file_directories[$type] ?? 'any';
|
||||
}
|
||||
|
||||
public static function getFileName($type, $id, $file)
|
||||
public static function getFileName($type, $id)
|
||||
{
|
||||
$extension = $file->getClientOriginalExtension();
|
||||
|
||||
return $type . '-' . $id .'-'.Str::random(10).'.'.$extension;
|
||||
return $type . '-' . $id . '-' . Str::random(10);
|
||||
}
|
||||
|
||||
public static function storeFile($type, $id, $file)
|
||||
{
|
||||
$fileName = self::getFileName($type, $id, $file);
|
||||
$fileName = self::getFileName($type, $id);
|
||||
$directory = self::getDirectory($type);
|
||||
$path = $directory . $fileName;
|
||||
$file->storeAs($directory, $fileName);
|
||||
$extension = $file->getClientOriginalExtension();
|
||||
$path = $directory . $fileName . '.' . $extension;
|
||||
$file->storeAs('public/' . $directory, $fileName . '.' . $extension);
|
||||
return $path;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user