<?php namespace App\Http\Controllers; use App\Models\WorkerDocument; use Illuminate\Http\Request; use Illuminate\Support\Facades\Storage; class DocumentController extends Controller {public function index(){return view('documents.index',['documents'=>WorkerDocument::with('user')->latest()->paginate(25)]);}public function store(Request $r){$d=$r->validate(['user_id'=>'required|exists:users,id','document_type'=>'required|string|max:80','title'=>'required|string|max:180','file'=>'required|file|max:10240','issued_on'=>'nullable|date','expires_on'=>'nullable|date']);$d['file_path']=$r->file('file')->store('hr-documents','local');$d['uploaded_by']=$r->user()->id;$d['is_private']=true;unset($d['file']);WorkerDocument::create($d);return back()->with('success','Private document uploaded.');}public function download(WorkerDocument $document,Request $r){abort_unless($r->user()->hasRole('founder','hr')||$document->user_id===$r->user()->id,403);return Storage::disk('local')->download($document->file_path,$document->title);}}