You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
1.7 KiB
75 lines
1.7 KiB
<?php
|
|
|
|
namespace App;
|
|
|
|
use App\HiLib\Models\Model;
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
class File extends Model
|
|
{
|
|
protected $table = 'files';
|
|
|
|
protected $fillable = [
|
|
'user_id', 'business_id', 'project_id', 'disk', 'original_name', 'name',
|
|
'extension', 'mime', 'group','size', 'description'
|
|
];
|
|
|
|
protected $casts = [];
|
|
|
|
public function rules()
|
|
{
|
|
return [
|
|
'user_id' => 'required',
|
|
'business_id' => 'required',
|
|
'project_id' => 'required',
|
|
'original_name' => 'required',
|
|
'name' => 'required',
|
|
'extension' => 'required',
|
|
'size' => 'required',
|
|
'description' => 'nullable',
|
|
];
|
|
}
|
|
|
|
|
|
public function user()
|
|
{
|
|
return $this->belongsTo(User::class, 'user_id','id','id',__FUNCTION__);
|
|
}
|
|
|
|
public function business()
|
|
{
|
|
return $this->belongsTo(Business::class, 'business_id', 'id', 'id', __FUNCTION__);
|
|
}
|
|
|
|
public function project()
|
|
{
|
|
return $this->belongsTo(Project::class, 'project_id', 'id', 'id', __FUNCTION__);
|
|
}
|
|
|
|
public function updateRelations()
|
|
{
|
|
|
|
}
|
|
|
|
public function reportActivity()
|
|
{
|
|
|
|
}
|
|
|
|
public function getPath()
|
|
{
|
|
return $this->business->id . \DIRECTORY_SEPARATOR . $this->project->id . DIRECTORY_SEPARATOR . $this->name;
|
|
}
|
|
|
|
public function getTemporaryLink()
|
|
{
|
|
return Storage::disk('s3')->temporaryUrl(
|
|
$this->getPath(),
|
|
\Carbon\Carbon::now()->addMinutes(15),
|
|
[
|
|
'Content-Type' => $this->mime,
|
|
'Content-Disposition' => $this->original_name,
|
|
]
|
|
);
|
|
}
|
|
}
|