| 1234567891011121314151617181920212223242526272829303132333435363738394041 |
- <?php
- namespace App\Services;
- use App\Models\KanbanMedia;
- use Illuminate\Database\Eloquent\Collection;
- use Illuminate\Http\UploadedFile;
- use Illuminate\Support\Facades\Storage;
- class KanbanMediaService
- {
- public function getByKanban(int $kanbanId): Collection
- {
- return KanbanMedia::with('user')
- ->where('kanban_id', $kanbanId)
- ->orderBy('created_at', 'desc')
- ->get();
- }
- public function create(int $kanbanId, int $userId, UploadedFile $file): KanbanMedia
- {
- $fileUrl = $file->store('kanban-media');
- $model = KanbanMedia::create([
- 'kanban_id' => $kanbanId,
- 'user_id' => $userId,
- 'file_name' => $file->getClientOriginalName(),
- 'file_url' => $fileUrl,
- 'mime_type' => $file->getMimeType(),
- ]);
- return $model->load('user');
- }
- public function delete(int $kanbanId, int $id): bool
- {
- $model = KanbanMedia::where('kanban_id', $kanbanId)->findOrFail($id);
- Storage::delete($model->file_url);
- return $model->delete();
- }
- }
|