@dalton_moen
To upload a PDF document in Laravel, you can follow these steps:
1 2 3 4 5 |
<form action="{{ route('upload') }}" method="POST" enctype="multipart/form-data"> @csrf <input type="file" name="pdf_document"> <button type="submit">Upload PDF</button> </form> |
1
|
Route::post('/upload', 'UploadController@upload')->name('upload'); |
1
|
php artisan make:controller UploadController |
Then, in the UploadController.php file, add the following code to handle the file upload:
1 2 3 4 5 6 7 8 9 10 11 |
public function upload(Request $request) { $request->validate([ 'pdf_document' => 'required|mimes:pdf|max:2048', ]); $pdfDocument = $request->file('pdf_document'); $pdfDocument->move(public_path('uploads'), $pdfDocument->getClientOriginalName()); return redirect()->back()->with('success', 'PDF document has been uploaded successfully.'); } |
Remember to handle errors and validations properly in your code to ensure a secure and smooth upload process.