Step 1: Update Your Database Credentials
Open the .env
file in the root of your Laravel project and update the database connection info like this:
⚠️ Make sure the database
laravel_learn
exists in your MySQL server.
Then run:
Step 2: File Upload Form (Blade View)
Create a Blade file at resources/views/form.blade.php
and paste the following code:
Step 3: Create Controller
Run the following command to create a controller:
Now, update the controller (app/Http/Controllers/FormController.php
) with this code:
Step 4: Define Routes
Open routes/web.php
and add these routes:
Step 5: Create Migration
Create a migration file:
Edit the migration (database/migrations/xxxx_xx_xx_create_uplaod_tbl_table.php
):
🔧 Note: The table name
uplaod_tbl
has a typo. It's better to useupload_tbl
, but if you're sticking with the current name, just be consistent.
Step 6: Migrate the Table
Run the migration:
Step 7: Run the Laravel App
Start the local server:
Open your browser and go to:
You'll see your file upload form ready to use.
Let me know if you want to:
-
Store files in
public/
instead ofstorage/app/
-
Show uploaded files below the form
-
Enable downloading or deleting files
-
Use an Eloquent model instead of DB facade