mirror of
https://bitbucket.org/studiotem/jandl-taskmanager-app.git
synced 2026-10-21 14:29:34 +00:00
attachments upload
This commit is contained in:
1 parent
7cec94337b
commit
ed3300ad29
9 files changed
+689
-12
No files matched your search
@@ -4,15 +4,47 @@ namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class Attachment extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
public $timestamps = true;
|
||||
public $guarded = ['id'];
|
||||
|
||||
public function mastertask()
|
||||
{
|
||||
return $this->belongsTo(MasterTask::class, 'master_task_id');
|
||||
}
|
||||
|
||||
public function subtask()
|
||||
{
|
||||
return $this->belongsTo(SubTask::class, 'sub_task_id');
|
||||
}
|
||||
|
||||
public static function uploadAttachmentsToS3($request, $mastertask)
|
||||
{
|
||||
$attachmentDataArray = [];
|
||||
|
||||
foreach ( $request as $file ) {
|
||||
$extension = $file->getClientOriginalExtension();
|
||||
$disk_name = uniqid() . '.' . $extension;
|
||||
|
||||
$path = 'jandl_taskmanager/attachments/' . $mastertask->id . '/' . $disk_name;
|
||||
|
||||
Storage::disk('s3')->put($path, $file->getContent(), 'public');
|
||||
|
||||
$attachmentDataArray[] = [
|
||||
'original_name' => $file->getClientOriginalName(),
|
||||
'disk_name' => $disk_name,
|
||||
'path' => Storage::disk('s3')->url($path),
|
||||
'extension' => $extension,
|
||||
'content_type' => $file->getMimeType(),
|
||||
'file_size' => $file->getSize(),
|
||||
];
|
||||
}
|
||||
|
||||
return $attachmentDataArray;
|
||||
}
|
||||
}
|
||||
@@ -37,6 +37,11 @@ class MasterTask extends Model
|
||||
{
|
||||
$users = $this->subtasks->pluck('user')->unique();
|
||||
|
||||
// ak nie je uvedeny ziaden team, tak sa vratia vsetci useri
|
||||
if (!$this->team){
|
||||
return $users;
|
||||
}
|
||||
|
||||
return $users->filter(function ($user) {
|
||||
return !in_array($this->team->id, $user->teams->pluck('id')->unique()->toArray());
|
||||
});
|
||||
|
||||
@@ -31,6 +31,11 @@ class SubTask extends Model
|
||||
{
|
||||
return $this->hasMany(Timesheet::class);
|
||||
}
|
||||
|
||||
public function attachments()
|
||||
{
|
||||
return $this->hasMany(Attachment::class);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user