Laravel Course Summary

Jul 26, 2024

Laravel Course Notes

Overview

  • Instructor: Victor
  • Course goal: Build an Instagram clone using Laravel.

Key Features of the Instagram Clone

  • Follow/Unfollow functionality
  • Edit profiles and change profile images
  • Image resizing using Intervention library
  • User authentication (registration, login/logout)
  • Adding new posts with captions and images
  • Displaying user feeds

What is Laravel?

  • Fastest growing open-source PHP framework.
  • Number one framework on GitHub.
  • Suitable for projects of all sizes.
  • Great community support.

Setting Up Laravel

  1. Install Composer - dependency package manager for PHP.
  2. Install Node.js and NPM (Node Package Manager).
  3. Install Laravel Installer using Composer.
    • Command: composer global require laravel/installer
  4. Create a new Laravel project:
    • Command: laravel new FreeCodeGram
  5. Open the project in PHPStorm.

Laravel File Structure

  • Composer.json: Contains project dependencies.
  • Artisan: Command line tool for various operations in Laravel.
  • Resources/views: For HTML markup and Blade templates.
    • Blade: Laravel templating engine.
  • Migrations: Database migration files to version control the database.

Working with Authentication

  • Use command: php artisan make:auth to scaffold authentication.
  • This will create the login and registration forms and user model.

Installing Frontend Frameworks

  • Laravel ships with Bootstrap and Vue.js.
  • Use NPM for managing JavaScript dependencies:
    • Command: npm install
    • Compile with: npm run dev or npm run watch

Setting Up Database

  • Use SQLite for simplicity in development.
  • Setup database connection in .env file:
    • Change DB_CONNECTION to sqlite.
  • Run migrations with command: php artisan migrate.

Eloquent Model Relationships

  • User profile relations, use hasOne for user and profile.
  • Posts relation, use hasMany for user and posts.
  • For posts, use a pivot table for many-to-many relationships (user follows profile).

Creating Mailable Emails

  • Command: php artisan make:mail NewUserWelcomeMail --markdown=emails.welcome
  • Setup email content using Markdown.
  • Send email after a user registers.

Caching in Laravel

  • Use Laravel's caching feature to cache database queries.
  • Command: php artisan cache:clear for clearing cache.

Sending Follow Requests

  • Setup Axios for handling follow/unfollow in Vue.js component.
  • Toggle follows using Laravel's many-to-many relationship utility.
  • Implement policies to restrict actions based on user roles.

Testing the Application

  • Regularly test the application on various profiles to ensure proper functionality.
  • Monitor performance using Laravel Telescope to see all the requests, events, etc.

Final Thoughts

  • Read Laravel's official documentation for in-depth understanding.
  • Stay updated on Laravel news for community developments.
  • Subscribe to the instructor's YouTube channel for additional content and tutorials.