Getting Started with Laravel Framework

Aug 10, 2024

Laravel Crash Course Notes

Course Overview

  • Perfect starting point for those with decent knowledge of Object-Oriented Programming and PHP.
  • Focus on learning and using Laravel to build a personal notes application.
  • Features include:
    • Registering and verifying email addresses
    • User login
    • CRUD (Create, Read, Update, Delete) operations for personal notes

Course Contents

  1. Environment Setup

    • PHP Installation
      • Recommended: XAMPP (includes MariaDB, PHP, and Apache)
    • Composer: PHP package manager
    • Node.js and npm: Required for Vite (asset bundler used by Laravel)
    • Git Bash: Recommended for terminal operations
    • VS Code: Development environment for the course
  2. Installing Laravel

    • Command to create Laravel project:
      composer create-project laravel/laravel laravel-11-crash-course  
      
  3. Deployment

    • Options for deploying Laravel applications:
      • Shared Hosting
      • VPS Hosting
      • Deployment using GitHub Actions and CI/CD pipelines
      • Hosting provider recommendation: Hostinger
  4. Laravel File and Folder Structure

    • Key Directories:
      • app/: Contains application logic (Models, Controllers, etc.)
      • config/: Configuration files
      • database/: Migrations, seeders, factories
      • resources/: Views, CSS, JS
      • public/: Entry point for the web server
      • storage/: Logs, compiled views, and sessions
      • tests/: Contains unit tests
      • vendor/: Third-party packages
  5. Artisan CLI

    • Commands for creating models, migrations, controllers, etc.
    • Example command to list available Artisan commands:
      php artisan list  
      

Creating Note Application

  1. Database Setup

    • Create a Note model and corresponding migration:
      php artisan make:model Note -m  
      
    • Update migration file to create notes table with necessary fields.
    • Run migrations:
      php artisan migrate  
      
  2. Seeding Data

    • Create a factory for generating fake data:
      php artisan make:factory NoteFactory --model=Note  
      
    • Create a seeder to populate the database with sample notes.
    • Run seeder:
      php artisan db:seed  
      
  3. Controllers and Routes

    • Create a resource controller for notes:
      php artisan make:controller NoteController --resource  
      
    • Define routes in web.php using resource routes.
    • Implement CRUD operations in NoteController.
  4. Views

    • Create views for listing, creating, editing, and showing notes.
    • Use Blade templating features for rendering views.
  5. User Authentication

    • Install Laravel Breeze for user registration and authentication:
      composer require laravel/breeze --dev  
      php artisan breeze:install  
      
    • Implement email verification by modifying the User model to implement MustVerifyEmail interface.
  6. Final Touches

    • Add necessary error handling and user feedback (session messages).
    • Style the application with Tailwind CSS.

Conclusion

  • Covered key concepts of Laravel and built a functional notes application.
  • Encouraged to explore further Laravel features and continue learning.