Laravel Interview Questions Tutorial

Jul 10, 2024

Laravel Interview Questions Tutorial

Introduction

  • Presenter: Iamin
  • Channel: Webtech Knowledge
  • Topic: Laravel interview questions (Beginner to Advanced)
  • Content covers ~20+ questions likely in interviews, with a focus on key areas to expect.

Beginner Questions

What is Laravel?

  • Free, open-source PHP web framework
  • Follows the Model-View-Controller (MVC) architecture

Benefits of Laravel over Other Frameworks

  • Inbuilt authentication system
  • Support for multiple file systems
  • Eloquent ORM (Object Relation Mapping)
  • Preloaded packages: Laravel Socialite, Laravel Cashier, Passport, and Laravel Scout
  • Artisan commands for database and structure

Explain Migrations in Laravel

  • Version control for the database
  • Command to generate migration: php artisan make:migration [table_name]

Packages Provided by Laravel

  • Cashier: Subscription-based billing
  • Passport: API authentication
  • Scout: Full-text search
  • Socialite: Login using Facebook, Twitter, Google, etc.

Implementing Soft Delete in Laravel

  • Soft delete: Doesn't display data but keeps it in the database
  • Use use SoftDeletes in the model
  • Add table->softDeletes() in the migration

Request Validation in Laravel

  • Use request->validate() method
  • Define rules for fields like title, email, password, etc.

Artisan Command Line Tool

  • Used to create controllers, models, migrations, seeders, factories, policies, etc.
  • Example: php artisan make:controller [ControllerName]

Full Stack Development with Laravel

  • Supports both frontend and backend development

Service Providers in Laravel

  • Tools for dependency injection and management
  • Commands: php artisan make:provider [ProviderName]
  • Common functions: register(), boot()

Eloquent Object Relationship Mapper (ORM)

  • Represents database tables as classes
  • Binds object instances to specific table rows

Middleware in Laravel

  • Verifications (e.g., user authentication, user type)
  • Command: php artisan make:middleware [MiddlewareName]
  • Register middleware in kernel.php

Verify CSRF Token

  • Class: VerifyCsrfToken extends BaseVerifier
  • Protects against CSRF attacks by default
  • Specify routes to bypass CSRF check using protected $except

Traits in Laravel

  • Allows methods to be reused across independent classes
  • Example usage: class Post { use Sharable; }

Throttling in Laravel

  • Limits the number of requests from a specific IP
  • Helps prevent DDoS attacks

Aggregate Methods in Query Builder

  • Methods: count, max, min, avg, sum

Routing in Laravel

  • Maps requests to controller functions

Declaring Global Variables

  • Defined in .env file or config.php

Seeding in Laravel

  • Inserting test data into the database

Supported Databases

  • MySQL, PostgreSQL, SQLite, SQL Server

File Validation

  • Example: Required file types and size limits

Advanced Questions

Purpose of Sessions

  • Store data and keep track of users

CSRF Token

  • Protects against CSRF attacks
  • Included in forms for security

GET vs POST Methods

  • GET: Retrieve data
  • POST: Submit data to the database

Common Status Codes

  • 401: Unauthorized
  • 402: Payment required
  • 403: Forbidden
  • 404: Not found
  • 500: Internal server error
  • 501: Not implemented
  • 503: Service unavailable

Sending Emails in Laravel

  • Tools: Mailtrap, Mailgun, Postmark, Swift Mailer

Clearing Cache

  • Commands:
    • php artisan config:clear
    • php artisan cache:clear
    • composer dump-autoload
    • php artisan route:clear

Database Configuration

  • Defined in .env file

Generating Application Key

  • Command: php artisan key:generate

Extending Login Expiration

  • Update lifetime variable in config/session.php

Rolling Back Migrations

  • Command: php artisan migrate:rollback --step=1

Checking Current Route Name

  • Command: request()->route()->getName()

Conclusion

  • Tutorial aims to prepare for Laravel interviews
  • Subscribe to the channel for more tutorials