Laravel: Introduction
Laravel is an open-source PHP framework that follows the MVC pattern, designed to make web development more enjoyable and productive.
Installation
bash
composer create-project laravel/laravel my-project
cd my-project
php artisan serveRouting
php
// routes/web.php
Route::get('/', function () {
return view('welcome');
});
Route::get('/users/{id}', function ($id) {
return "User: $id";
});
Route::post('/contact', [ContactController::class, 'store']);Eloquent ORM
php
// Model
class User extends Model {
protected $fillable = ['name', 'email', 'password'];
public function posts() {
return $this->hasMany(Post::class);
}
}
// Query
$users = User::where('active', true)->orderBy('name')->get();
$user = User::find(1);Middleware
php
// app/Http/Middleware/CheckAge.php
public function handle($request, Closure $next) {
if ($request->age < 18) {
return redirect('home');
}
return $next($request);
}Conclusion
Laravel simplifies PHP development with powerful tools like Eloquent, migrations and the built-in authentication system.