Hi Kamal
In Laravel, handling file uploads is quite straightforward. Here’s a simple example:
Create a form in your Blade file:
<form action="{{ route('upload') }}" method="POST" enctype="multipart/form-data"> @csrf <input type="file" name="file"> <button type="submit">Upload</button> </form>Add a route in web.php:
Route::post('/upload', [FileController::class, 'store'])->name('upload');
Handle the upload in your controller (FileController):
public function store(Request $request) { $request->validate([ 'file' => 'required|mimes:jpg,png,pdf|max:2048', ]);
$path = $request->file('file')->store('uploads', 'public');
return back()->with('success', 'File uploaded successfully!')->with('path', $path);
}
The file will be stored in storage/app/public/uploads,
and you can access it via storage_link (php artisan storage:link).
That’s it — Laravel handles most of the work for you. If you need more control (like renaming files, saving paths to the database, etc.), you can easily extend this logic.
Best regards, [Rivael Saputra]
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.