Skip to main content

Posts

How Composer Autoloading Works in Laravel (Complete Guide)

How Composer Autoloading Works in Laravel (Complete Guide) When building with Laravel , you rarely need to manually include PHP files. That’s thanks to Composer autoloading — a feature that automatically loads the necessary classes when you need them. In this guide, you’ll learn how Composer autoloading works in Laravel , how PSR-4 fits in, and how to use it effectively in your own code. What is Composer Autoloading? Composer is Laravel’s dependency manager. One of its most powerful features is autoloading — it automatically loads PHP classes so you don’t have to write require or include statements manually. It works by following a standardized naming and directory structure defined by PSR-4 . How PSR-4 Autoloading Works PSR-4 is a PHP standard that defines how to map namespaces to file paths. Composer uses this standard to find and load your classes automatically. In Laravel, you ca...
Recent posts

How to Remove a Package from Laravel using Composer (Step-by-Step Guide)

How to Remove a Package from Laravel using Composer (Step-by-Step Guide) When working with Laravel , you often install multiple Composer packages to extend functionality. But what if you no longer need one? In this guide, you’ll learn the correct way to remove a package from Laravel using Composer — safely and cleanly. Step 1: Identify the Package Name To begin, open your composer.json file or run the following command in your Laravel project root: composer show This lists all installed Composer packages. Find the exact name of the one you want to remove — for example, barryvdh/laravel-debugbar . Step 2: Remove the Package Use the composer remove command to uninstall it: composer remove barryvdh/laravel-debugbar This command will: Uninstall the package from your Laravel project. Update the composer.json and composer.lock files. Automatically clean up the...

PHP Basics: Understanding Variables, Data Types, and Constants

PHP Basics: Understanding Variables, Data Types, and Constants PHP is one of the most popular server-side scripting languages used to develop dynamic websites and web applications. Before diving into complex programming concepts, it’s crucial to understand the basics, especially variables, data types, and constants . 1. Variables in PHP Variables are used to store data that can be manipulated during the execution of a program. In PHP, a variable starts with the $ symbol followed by the variable name. <?php $name = "John Doe"; // String variable $age = 25; // Integer variable $is_student = true; // Boolean variable ?> Rules for naming PHP variables: Must start with a $ sign followed by a letter or underscore. Can contain letters, numbers, and underscores. Variable names are case-sensitive ( $name is different from $Name ). ...

How to Set Up & Use Laravel Telescope

How to Set Up & Use Laravel Telescope Laravel Telescope is a powerful debugging and monitoring tool built by the Laravel team. It provides detailed insights into your application’s requests, exceptions, database queries, jobs, mail, notifications, cache, and more—all in an elegant dashboard. 🚀 What is Laravel Telescope? Laravel Telescope acts as a “developer’s black box,” recording everything that happens within your Laravel app. It’s especially useful during development and staging to track performance issues, failed jobs, or unexpected behavior. 🧩 Step 1: Install Telescope Run the following Composer command in your Laravel project directory: composer require laravel/telescope --dev The --dev flag ensures Telescope is only installed in your local development environment. ⚙️ Step 2: Publish Telescope Assets Once the package is installed, publish the Telescope service provider and assets: php artisan tel...

Laravel Authentication: Sanctum vs Passport

Laravel Authentication: Sanctum vs Passport (with Examples) Laravel offers two main authentication packages: Sanctum and Passport . Both solve different problems — Sanctum is lightweight and best for SPAs and mobile apps, while Passport is a full OAuth2 server solution. Let’s break it down with examples and comparisons. 1. Quick Comparison Feature Sanctum Passport Use case First-party SPA & simple API tokens Full OAuth2 server with scopes, grants Complexity Simple, easy to setup Advanced, more config needed Token type Personal access tokens, SPA cookies Access + Refresh tokens Best for Single backend apps, mobile APIs Third-party integrations, OAuth2 2. Sanctum Setup Example Sanctum is great for issuing API tokens and handling SPA cookie-based auth. Here’s how to set i...

Laravel Tips & Tricks Every Fresher Should Know

Laravel Tips & Tricks Every Fresher Should Know Laravel is one of the most beginner-friendly yet powerful PHP frameworks. If you’re just starting your Laravel journey, here are some practical tips and tricks that will make your development process smoother, cleaner, and more professional. 1. Setup & Environment Always configure your .env file correctly. Keep secrets (like DB passwords, API keys) out of version control. Use php artisan config:cache in production for performance. composer create-project laravel/laravel my-app cd my-app php artisan key:generate 💡 Pro Tip: Don’t forget to ignore .env in git and use .env.example instead. 2. Master Artisan Artisan is Laravel’s command line tool that saves time and reduces repetitive work. php artisan list — list all commands php artisan make:controller PostController --resource — generate resourceful controller php artisan route...

Difference Between Service Provider & Service Container in Laravel

Difference Between Service Provider & Service Container in Laravel In Laravel, two important concepts are Service Container and Service Provider . They work hand in hand to make your code clean, testable, and flexible. If you’re new to Laravel, don’t worry — let’s break it down step by step with simple examples. 1. What is the Service Container? The Service Container is the heart of Laravel’s dependency injection system . It’s basically a container (or box) that holds all the classes, objects, and services your application might need. Think of the Service Container as a toolbox . Whenever your code asks for a “tool” (a class or service), Laravel looks inside the toolbox and gives it to you. Example: // Binding a class in the container app()->bind('PaymentGateway', function () { return new \App\Services\PayPalPayment(); }); // Resolving it later $payment = app()->make('PaymentG...