feat: Initialize core application structure including authentication, role-based dashboards, service task management, and integration workflows.
This commit is contained in:
46
app/Http/Controllers/AttachmentController.php
Normal file
46
app/Http/Controllers/AttachmentController.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Attachment;
|
||||
use App\Models\ServiceTask;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class AttachmentController extends Controller
|
||||
{
|
||||
public function store(Request $request, ServiceTask $task)
|
||||
{
|
||||
$request->validate([
|
||||
'file' => 'required|file|max:10240', // 10MB max
|
||||
]);
|
||||
|
||||
$file = $request->file('file');
|
||||
$originalName = $file->getClientOriginalName();
|
||||
$filename = time() . '_' . $originalName;
|
||||
$path = $file->storeAs('attachments/' . $task->id, $filename, 'public');
|
||||
|
||||
$attachment = $task->attachments()->create([
|
||||
'filename' => $filename,
|
||||
'original_name' => $originalName,
|
||||
'path' => $path,
|
||||
'mime_type' => $file->getMimeType(),
|
||||
'size' => $file->getSize(),
|
||||
]);
|
||||
|
||||
return back()->with('success', 'Fichier ajouté avec succès.');
|
||||
}
|
||||
|
||||
public function download(Attachment $attachment)
|
||||
{
|
||||
return Storage::disk('public')->download($attachment->path, $attachment->original_name);
|
||||
}
|
||||
|
||||
public function destroy(Attachment $attachment)
|
||||
{
|
||||
Storage::disk('public')->delete($attachment->path);
|
||||
$attachment->delete();
|
||||
|
||||
return back()->with('success', 'Fichier supprimé.');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user