📖 Scenario: You are starting a new web application using Laravel. To build it well, you need to understand how Laravel organizes its files and folders.
🎯 Goal: Learn the basic Laravel project structure by creating key folders and files in the right places.
📋 What You'll Learn
Create the main Laravel project folder structure
Add a configuration file for database settings
Create a simple route in the routes file
Add a basic controller file
💡 Why This Matters
🌍 Real World
Laravel projects follow this structure to keep code organized and easy to maintain. Understanding this helps you build web apps faster.
💼 Career
Knowing Laravel's project structure is essential for backend web developer roles using PHP and Laravel framework.
Progress0 / 4 steps
1
Create the main Laravel folders
Create a Laravel project folder structure with these exact folders inside the main laravel_project folder: app, config, routes, and public.
Laravel
Hint
Think of these folders as the main parts of your Laravel app: app for code, config for settings, routes for URLs, and public for web files.
2
Add a database configuration file
Inside the config folder, create a file named database.php with a PHP array variable called $databaseConfig that has keys 'host' set to '127.0.0.1' and 'database' set to 'laravel_db'.
Laravel
Hint
Use a PHP array to hold the database settings inside database.php.
3
Create a simple route
Inside the routes folder, create a file named web.php. Add a route using Route::get that listens to the URL '/' and returns the string 'Welcome to Laravel'.
Laravel
Hint
Routes define what happens when someone visits a URL. Use Route::get for a GET request.
4
Add a basic controller
Inside the app folder, create a PHP file named HomeController.php. Define a class HomeController with a public method index that returns the string 'Home Page'.
Laravel
Hint
Controllers hold the logic for your pages. Define a class and a method that returns a string.
Practice
(1/5)
1. Which folder in a Laravel project contains the files that define the URL routes for the application?
easy
A. config
B. app
C. resources
D. routes
Solution
Step 1: Understand the purpose of the routes folder
The routes folder holds files that define how URLs map to code actions in Laravel.
Step 2: Compare with other folders
The app folder contains core code, resources holds views and assets, and config stores configuration settings.
Final Answer:
routes -> Option D
Quick Check:
URL routes = routes folder [OK]
Hint: Routes are always in the routes folder [OK]
Common Mistakes:
Confusing app with routes folder
Thinking views are in routes
Mixing config files with routes
2. Which of the following is the correct path to store Blade template files in a Laravel project?
easy
A. public/templates
B. app/Views
C. resources/views
D. config/views
Solution
Step 1: Identify where Blade templates are stored
Blade templates are stored in the resources/views folder by Laravel convention.
Step 2: Verify other options
app/Views is not standard, public/templates is for public assets, and config/views is not used for templates.
Final Answer:
resources/views -> Option C
Quick Check:
Blade templates = resources/views [OK]
Hint: Templates live in resources/views folder [OK]