beginner Step 1 of 15

Introduction to Laravel

Laravel Framework

Introduction to Laravel

Laravel is the most popular PHP framework, created by Taylor Otwell in 2011. It provides an elegant, expressive syntax while giving you the tools needed for large, robust applications. Laravel follows the MVC (Model-View-Controller) architectural pattern and comes with built-in solutions for routing, authentication, database ORM (Eloquent), templating (Blade), testing, queues, and much more. Its vibrant ecosystem includes tools like Sail (Docker), Forge (deployment), Vapor (serverless), and Nova (admin panels).

Installation

# Install Laravel via Composer
composer create-project laravel/laravel my-project
cd my-project

# Or use the Laravel installer
composer global require laravel/installer
laravel new my-project

# Start development server
php artisan serve
# => http://localhost:8000

# Directory structure
my-project/
├── app/                 # Application code
│   ├── Http/
│   │   ├── Controllers/
│   │   └── Middleware/
│   ├── Models/
│   └── Providers/
├── config/              # Configuration files
├── database/
│   ├── migrations/      # Database schema
│   ├── seeders/         # Test data
│   └── factories/       # Model factories
├── resources/
│   └── views/           # Blade templates
├── routes/
│   ├── web.php          # Web routes
│   └── api.php          # API routes
├── storage/             # Logs, cache, uploads
├── tests/               # Feature and unit tests
├── .env                 # Environment configuration
├── artisan              # CLI tool
└── composer.json

Artisan CLI

# Common artisan commands
php artisan list                    # Show all commands
php artisan make:model Post -mcr    # Model + Migration + Controller + Resource
php artisan make:controller UserController --resource
php artisan migrate                 # Run database migrations
php artisan migrate:rollback        # Undo last migration
php artisan db:seed                 # Run database seeders
php artisan tinker                  # Interactive REPL
php artisan route:list              # Show all registered routes
php artisan cache:clear             # Clear application cache
php artisan config:clear            # Clear config cache
Pro tip: Use php artisan make:model Post -mcr to generate a model, migration, and resource controller in one command. The tinker command opens an interactive shell where you can test Eloquent queries and application logic without writing routes or controllers.

Key Takeaways

  • Laravel is PHP's most popular framework with built-in solutions for routing, ORM, auth, and more.
  • Use composer create-project to start new projects and php artisan serve for development.
  • The artisan CLI generates boilerplate code, runs migrations, and manages your application.
  • Laravel follows MVC: Models in app/Models/, Views in resources/views/, Controllers in app/Http/Controllers/.
  • Environment configuration lives in .env — never commit this file to version control.