Belajar Laravel 11 | 3. Struktur Folder
Table of Contents
Introduction
This tutorial provides a comprehensive overview of the folder structure in Laravel 11, highlighting the differences from previous versions. Understanding this structure is crucial for effectively developing applications using the Laravel framework.
Step 1: Explore the Folder Structure
Familiarize yourself with the new, more streamlined folder structure of Laravel 11. Here are the main directories you will encounter:
- app: Contains the core application code, including models, controllers, and services.
- bootstrap: Holds files for bootstrapping the framework and application.
- config: Contains configuration files for various services and features.
- .env: The environment file for setting up application environment variables.
Step 2: Understand Each Folder's Purpose
Dive deeper into the purpose of each key folder:
-
app & bootstrap
- app: Organize your business logic here. It includes:
- Models: Define your database structure.
- Controllers: Handle the application logic.
- Services: Manage various functionalities.
- bootstrap: Initializes the application, ensuring all necessary components are loaded.
- app: Organize your business logic here. It includes:
-
config & .env
- config: Adjust settings for:
- Database connections
- Mail services
- Session management
- .env: Customize your app's environment settings (e.g., database credentials, application key).
- config: Adjust settings for:
Step 3: Explore Additional Directories
Familiarize yourself with other important directories:
-
database
- Contains migration files, seeders, and factories for database management.
-
public
- The entry point for web requests. Include assets like CSS, JavaScript, and images here.
-
resources
- Store views, raw assets (SASS, JavaScript), and language files.
-
routes
- Define your application routes, specifying how URLs map to controllers and actions.
-
vendor
- Contains third-party packages installed via Composer. Do not modify this directory directly.
Step 4: Learn the MVC Architecture
Understand the Model-View-Controller (MVC) architecture that Laravel follows:
- Model: Represents data and business logic.
- View: The user interface, displaying data to users.
- Controller: Acts as an intermediary between models and views, processing user input and returning the appropriate response.
Step 5: Working with Views
Get started with creating and managing views:
- Create new views in the resources/views directory.
- Use Blade templating to render dynamic content efficiently.
Step 6: Sending Data to Views
Learn to send data from controllers to views:
- Use the
view()
function in your controller methods to pass data.
Example:
return view('welcome', ['name' => 'John']);
Conclusion
Understanding the Laravel 11 folder structure is essential for effective application development. Take time to explore each directory's purpose and how they interact within the MVC framework. As you begin building your application, refer back to this guide to ensure you're leveraging Laravel's capabilities efficiently. For further learning, explore additional Laravel tutorials or dive into creating your first application!