Hi Brothers ,
These questions cover a range of difficulty levels, from beginner to advanced.
Laravel is an open-source PHP web framework designed for building modern web applications. It follows the MVC (Model-View-Controller) architecture and provides features like routing, authentication, and caching.
Composer is a dependency manager for PHP. In Laravel, it is used to install and manage packages or libraries required by the application.
Artisan is Laravel’s built-in command-line tool for performing tasks like database migrations, scaffolding, and seeding.
Example: php artisan make:model User
Routing defines how application URLs map to specific controllers or closures.
Example: Route::get('/home', [HomeController::class, 'index']);
Middleware acts as a bridge between a request and a response. It is used for authentication, logging, or other pre-processing tasks.
php artisan make:middleware CheckAge
Middleware can be registered in the app/Http/Kernel.php
file under routeMiddleware
or middlewareGroups
.
Eloquent is Laravel’s built-in ORM (Object-Relational Mapper) for interacting with the database using an active record pattern.
Relationships can be defined using methods:
hasOne()
hasMany()
belongsTo()
belongsToMany()
Example:
public function posts() {
return $this->hasMany(Post::class);
}
find()
: Fetches a single record by its primary key.where()
: Adds query constraints, can fetch multiple records.A model represents a table in the database.
Example: php artisan make:model User
use SoftDeletes
in the model.deleted_at
column in the migration.A migration is a way to define database schema changes in a version-controlled manner.
Example: php artisan make:migration create_users_table
php artisan migrate
Database seeding is used to populate the database with test data.
Example: php artisan make:seeder UserSeeder
Laravel provides pre-built authentication functionality via the auth scaffold.
Example: php artisan make:auth
Auth::attempt()
: Attempts to log in a user with given credentials.Auth::check()
: Checks if a user is logged in.Guards define how users are authenticated for each request.
Example: web guard, API guard.
php artisan make:middleware CheckRole
Events are used to signal that an action has occurred, while listeners handle the action.
Example:
php artisan make:event UserRegistered
php artisan make:listener SendWelcomeEmail
Service providers are the central place for application configuration and bootstrapping.
Jobs handle specific tasks like sending emails, while queues allow jobs to be processed in the background.
Passport provides OAuth5 authentication for APIs.
The config
folder contains configuration files for various parts of the application, such as database settings (database.php
) and mail settings (mail.php
).