when you first create a Laravel project, you will see a set of folders and files in the root directory. Each of these folders has its role in the application

/app
The app directory is the heart of your application. This is where most of your code will live, including models, controllers, and any business logic.
/app/Http: This folder handles HTTP requests and responses.
/app/Http/Controllers: The Controllers folder is where you will create controllers that respond to specific routes and handle application logic.
/app/Http/Middleware: Middleware filters HTTP requests before they reach your controller. For example, you might use middleware to check if a user is authenticated before accessing certain routes.
php artisan make:controller Login-Controller
This command creates a new controller file in /app/http/Controllers
/
/app/Models: This is where your application’s models live. Models represent your database tables and allow you to interact with data using Laravel’s Eloquent ORM.
Creating a model
php artisan make:model Registration
This command generates a Registration.php file in /app/Modles/Registration.php
, which you can use to interact with the registration table in your database.
/app/Providers: Contains service providers, which are used to register services and bind classes to the Laravel container.
/bootstrap
The bootstrap directory isn’t something you will interact with often, but it’s essential. It handles the bootstrapping of Laravel, loading the core framework files and initializing settings.
/bootstrap/app.php: This file initializes the Laravel application and loads configuration settings.
/bootstrap/cache: This folder stores cached configurations and other optimization files, making your application run faster.
/config
The config directory contains all configuration files for your Laravel application. These files allow you to adjust settings for various services, including:
/config/app.php: Basic app configuration like timezone, locale, and debugging options.
/config/database.php: Database connection settings, including the type of database and authentication credentials.
/config/mail.php: Setting for sending emails.
Each configuration file is mapped to an environment variable in your .env file, making it easy to change setting between different environments (e.g., development, testing, production).
Example: Changing the application name.
- open .env and chnage APP_NAME-YourAppName.
- open /config/app.php set ‘name’=>env(‘APP_NAME’,’Laravel’)
These configuration are accessible in your application, allowing you to adapt settings without touching code in your controllers or models.
/database
This folder handles everything related to databases, including migrations, factories, and seeds
/database/migrations: Define the structure of your database tables. Migrations are version-controlled, so you can share database changes easily.
Example : Creating a Migration
artisan make:migration create_users_table
This creates a migration file in /database/migrations. inside, you ca define columns for the users table.
/database/factories: Factories allows you to quickly generate fake data for testing. Each Factory corresponds to a model and defines what ‘fake’ data should look like.
Example: Creating a factory.
artisan make:factory UserFactory
/database/seeds: Seeds are scripts that populate the database with data. You can use seeds to fill tables with initial or testing data.
Example: Creating a seeder.
php artisan make:seeder UserSeeder
/public
The Public folder is the root directory for all files accessible to the web. This is where your web server points to when serving your application.
/public/index.php: The main entry point for all requests to your Laravel application. This file loads the framework and routes the request to the correct controller.
/public/assets: The public folder is also where you should place static assets, such as images, JavaScript files, and CSS. For example, if you add a file image.png to the public folder, it would be accessible at http://localhost:8000/image.png.
/resources
The resources directory is where your application’s front-end code resides, including Blade templates, localization files, and raw assets like CSS and JavaScript (before they’re compiled).
/resources/views: The views folder contains Blade templates, which are HTML files with Blade syntax to handle dynamic content. You will use these templates to display pages to users.
Example : Create a Blade template.
- Create a new file, welcome.blade.php, in /resources/views.
- Add HTML content.
<h2>Welcome to Lavaravel!</h2> <h1>Hello world!</h1>
/resources/lang: This folder holds translation files for localization. Laravel makes it easy to support multiple languages, with separate files for each language.
/resources/css or /resources/js: Raw CSS and JavaScript files go here. You can use tools like Laravel Mix to compile them into optimized versions for production
/routes
The routes directory contains route definitions, which specify how the application should respond to requests.
/routes/web.php: Defines routes that return HTML views, making it idela for web0based applications.
/routes/api.php: Defines routes specifically for APIs, typically returning JSON data.
/routes/console.php: Allows you to define custom Artisan commands.
/routes/cahnnels.php: Defines broadcasting channels for real-time events.
Example: Adding a route in web.php
Route::get('/hello', function(){ return 'Hello world!' })
/storage
The storage folder contains files generates by Laravel, including logs, cached files, and session data.
/storage/app: Contains user-uploaded files and other application specific-data.
/storage/framework: Stores log files, including errors, warnings, and informational logs.
NOTE: Make sure to add appropriate permissions to the storage folder, as Laravel needs write access for storing logs and cache.
/tests
The tests directory is where you will find the default testing setup. Laravel comes with PHPUnit pre-configured, making it easy tow rite and run tests.
/tests/Feature: Contains tests for large feature of your application, usually covering multiple components.
/tests/Unit: Contains unit tests for testing individual classes or methods.
Example: Running tests.
php artisan test
Testing is a powerful way to ensure your applications functionality and maintain code quality, especially as the project grows.
/vendor
The vendor folder is managed by composer and contains all the dependencies and libraries required by Laravel and your application. You won’t interact with this folder directly, but it’s essential for running Laravel.
When you add or update a dependency using Composer, it’s stored in the vendor directory. This folder is generated by composer, so you don’t need to include it in version control; it can be easily rebuilt on another machine by running composer install.
The post Laravel project Folder and File structure appeared first on PHPGurukul.
Source: Read MoreÂ