Get ready for your next interview with our comprehensive question library
Laravel is a free, open-source PHP web framework following the MVC (Model-View-Controller) architectural pattern.
Key features:
MVC (Model-View-Controller) separates application logic:
Flow: Route → Controller → Model → Controller → View → Response
Composer is PHP's dependency manager. Laravel uses it to manage packages via composer.json
.
composer install # Install dependencies
composer update # Update dependencies
composer dump-autoload # Regenerate PSR-4 autoload
composer require package # Add new package
Routes are defined in routes/web.php
for web routes and routes/api.php
for API routes. Laravel supports various HTTP verbs:
Route::get('/users', [UserController::class, 'index']);
Route::post('/users', [UserController::class, 'store']);
Route::put('/users/{id}', [UserController::class, 'update']);
Route::delete('/users/{id}', [UserController::class, 'destroy']);
// Resource route (creates all CRUD routes)
Route::resource('posts', PostController::class);
Route parameters capture segments of the URI and pass them to your controller. There are required and optional parameters:
// Required parameter
Route::get('/user/{id}', function ($id) {
return "User ID: $id";
});
// Optional parameter
Route::get('/user/{name?}', function ($name = 'Guest') {
return "Hello, $name";
});
// Regular expression constraint
Route::get('/user/{id}', function ($id) {
//
})->where('id', '[0-9]+');
Resource controllers provide seven methods for CRUD operations:
// Generate: php artisan make:controller PostController --resource
// Route: Route::resource('posts', PostController::class);
Eloquent is Laravel's Active Record ORM. Each database table has a corresponding Model.
Advantages:
Upgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumAccess all premium content - interview questions, and other learning resources
We regularly update our features and content, to ensure you get the most relevant and updated premium content.
1000 monthly credits
Cancel anytime