feat: FileController para servir archivos privados con autenticación

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-26 13:58:50 -06:00
parent e42fca3c5b
commit 9dd5ac6cbf
5 changed files with 40 additions and 8 deletions
+1 -1
View File
@@ -55,7 +55,7 @@ class ChatController extends Controller
if ($request->hasFile('attachment')) {
$file = $request->file('attachment');
$attachment = $file->store('chat', 'uploads');
$attachment = $file->store('chat', 'local');
$mime = $file->getMimeType();
if (str_starts_with($mime, 'image')) $attachmentType = 'image';
+24
View File
@@ -0,0 +1,24 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\Storage;
class FileController extends Controller
{
/**
* Sirve archivos privados con autenticación.
* El parámetro $path incluye el módulo como primer segmento:
* chat/filename.jpg
* profiles/avatar.jpg
* tasks/homework.pdf
*/
public function serve(string $path)
{
if (!Storage::disk('local')->exists($path)) {
abort(404);
}
return Storage::disk('local')->response($path);
}
}