📚

Comprehensive Laravel Course Overview

Apr 18, 2025

Laravel Full Course Notes

Introduction

  • Instructor: Victor
  • Objective: Build an Instagram clone using Laravel from scratch.
  • Focus on coding with no breaks, extensive learning.

What is Laravel?

  • Fastest growing open-source PHP framework.
  • Number one framework on GitHub.
  • Easy for newcomers, powerful for enterprise projects.
  • Strong community support.

Installing Laravel

  1. Prerequisites:
    • General knowledge of PHP.
    • Composer installed (PHP dependency manager).
    • Node.js installed (includes NPM).
  2. Install Laravel:
    • Use the Laravel installer: composer global require laravel/installer.
  3. Create a new Laravel project:
    • Run command: laravel new FreeCodeGram.
  4. Open project in IDE (PHPStorm).

Laravel Project Structure

  • Composer.json file holds project assets.
  • Artisan command line tool for application management.

Artisan Commands

  • Run php artisan to see available commands.
  • Common commands: php artisan serve, php artisan make:auth for authentication.

Basic Authentication Setup

  • Use php artisan make:auth for user authentication setup.
  • Users can register, log in, log out, and manage profiles.

Laravel Views and Blade Syntax

  • Blade templating engine for rendering views.
  • Use resources/views to manage view files.
  • Blade syntax allows embedding PHP logic in views.

Creating Views

  1. Create a directory for each main feature (e.g., profiles, posts).
  2. Use Blade directives (e.g., @extends, @yield).
  3. Use {{ }} for variable output and @auth, @guest for conditional content.

Image Handling

  • Use the Intervention Image library for image resizing and manipulation.
  • Install with: composer require intervention/image.
  • Use in project with use Intervention\Image\Image.

User Profiles

  • Each user has a profile.
  • Profile creation upon user registration.
  • Store profile images in a public directory accessible by the application.

Caching

  • Use Laravel's caching features to optimize performance.
  • Use cache()->remember() to cache counts for followers, posts, etc.

Sending Emails

  • Use Laravel's Mailable feature to send emails (e.g., welcome email upon registration).
  • Configure mail settings in .env file.
  • Use Mail::to()->send(new WelcomeMail()) to send emails.

Policies

  • Use policies for authorization on user actions (e.g., updating profiles).
  • Create a policy with php artisan make:policy ProfilePolicy.
  • Implement authorization checks using the authorize() method.

Following Functionality

  • Implement many-to-many relationships for user follows.
  • Create a pivot table for profile_user.
  • Use belongsToMany in the User and Profile models.

Pagination

  • Use paginate() method in queries to limit results per page.
  • Render pagination links using {{ $posts->links() }} in Blade views.

Telescope

  • Laravel Telescope for monitoring application requests, queries, and logs.
  • Install with composer require laravel/telescope and run php artisan telescope:install.

Final Thoughts

  • Build a full-featured Instagram clone with user authentication, profile management, image uploads, and following functionality.
  • Explore Laravel documentation and Laravel community resources for continued learning.