SyntaxStudy
Sign Up
Laravel Laravel Directory Structure and Artisan CLI
Laravel Beginner 1 min read

Laravel Directory Structure and Artisan CLI

A fresh Laravel project follows a well-defined directory structure. The app/ directory contains the core application code — Models, Controllers, Policies, and Service Providers live here. The routes/ directory holds all route definitions split into web.php, api.php, console.php, and channels.php. Configuration files reside in config/, while environment-specific values are stored in the .env file at the project root. The Artisan command-line interface is one of Laravel's most powerful features. It provides dozens of built-in commands and can be extended with custom commands. Developers use Artisan to scaffold entire classes (php artisan make:model, php artisan make:controller), run database migrations, manage queues, and interact with the application via an interactive REPL called Tinker. Understanding the service container and service providers is key to leveraging Laravel's architecture. The service container is a powerful IoC container that resolves class dependencies automatically. Service providers in app/Providers/ are the central place to bind classes into the container, register event listeners, and bootstrap any application services during startup.
Example
# Make a new Eloquent model with migration, factory, and seeder
php artisan make:model Post -mfs

# Make a resourceful controller
php artisan make:controller PostController --resource --model=Post

# Make a form request for validation
php artisan make:request StorePostRequest

# Make a custom Artisan command
php artisan make:command SendWeeklyDigest

# Make a middleware
php artisan make:middleware EnsureEmailIsVerified

# Make an event and its listener
php artisan make:event OrderPlaced
php artisan make:listener SendOrderConfirmation --event=OrderPlaced

# Open the interactive Tinker REPL
php artisan tinker
# Inside Tinker:
# >>> App\Models\User::count()
# => 5
# >>> App\Models\Post::factory()->create(['title' => 'Hello'])

# Display all registered routes
php artisan route:list

# Cache routes for production
php artisan route:cache