This project is a pedagogical translation of Django's authentication system to Laravel, designed to learn Laravel by comparing it with Django/Python concepts.
For first-time setup after cloning from GitHub:
# Make the script executable (if needed)
chmod +x manage.sh
# Run the interactive manager
./manage.sh
# Select option 9: "๐ Configuraciรณn inicial completa"This will automatically:
- โ Check PHP and Composer dependencies
- โ Install Laravel dependencies
- โ
Create
.envfile from template - โ Generate application key (Laravel's SECRET_KEY)
- โ Setup SQLite database
- โ Run migrations
- โ Create test users
- โ Start the server automatically!
- โ Open browser automatically (if possible)
# Install PHP dependencies with Composer
composer install
# Copy environment configuration
cp .env.example .env
# Generate application key (equivalent to Django's SECRET_KEY)
php artisan key:generate
# Create SQLite database file
touch database/database.sqlite
# Run migrations to create tables
php artisan migrate
# Seed database with test users
php artisan db:seed --class=UserSeeder# Using manage.sh (recommended)
./manage.sh
# Then select option 1: "๐ Iniciar servidor Laravel"
# OR manually
php artisan serve
# Check server status anytime
./check-server.sh- Home: http://localhost:8000/
- Login: http://localhost:8000/auth/login
- Dashboard: http://localhost:8000/dashboard (requires authentication)
Test Users:
- Username:
admin| Email:admin@example.com| Password:password123 - Username:
testuser| Email:testuser@example.com| Password:password123
| Aspect | Django | Laravel |
|---|---|---|
| File | urls.py |
routes/web.php |
| Syntax | path('login/', login_view, name='login') |
Route::get('login', [AuthController::class, 'showLogin'])->name('login') |
| Parameters | path('user/<int:id>/', user_detail) |
Route::get('user/{id}', [UserController::class, 'show']) |
| Groups | include() or path() with prefix |
Route::prefix('auth')->group() |
| Aspect | Django | Laravel |
|---|---|---|
| File | views.py |
app/Http/Controllers/AuthController.php |
| Function | def login(request): |
public function login(Request $request) |
| Request | request.POST.get('username') |
$request->input('username') |
| Response | return render(request, 'template.html') |
return view('template') |
| Redirect | return redirect('home') |
return redirect()->route('home') |
| Aspect | Django | Laravel |
|---|---|---|
| File | models.py |
app/Models/User.php |
| Definition | class User(AbstractUser): |
class User extends Authenticatable |
| Fields | email = models.EmailField() |
protected $fillable = ['email'] |
| Queries | User.objects.all() |
User::all() |
| Create | User.objects.create() |
User::create() |
| Filter | User.objects.filter(active=True) |
User::where('active', true)->get() |
| Aspect | Django | Laravel |
|---|---|---|
| Create | python manage.py makemigrations |
php artisan make:migration |
| Run | python manage.py migrate |
php artisan migrate |
| Rollback | python manage.py migrate app 0001 |
php artisan migrate:rollback |
| Status | python manage.py showmigrations |
php artisan migrate:status |
| Aspect | Django | Laravel Blade |
|---|---|---|
| Inheritance | {% extends 'base.html' %} |
@extends('layouts.app') |
| Blocks | {% block content %}{% endblock %} |
@section('content') @endsection |
| Variables | {{ user.username }} |
{{ Auth::user()->username }} |
| Conditionals | {% if user.is_authenticated %} |
@auth @endauth |
| Loops | {% for item in items %} |
@foreach($items as $item) |
| CSRF | {% csrf_token %} |
@csrf |
| Aspect | Django | Laravel |
|---|---|---|
| Login | auth_login(request, user) |
Auth::login($user) |
| Logout | auth_logout(request) |
Auth::logout() |
| Current User | request.user |
Auth::user() |
| Is Authenticated? | user.is_authenticated |
Auth::check() |
| Protect Routes | @login_required decorator |
->middleware('auth') |
| Aspect | Django | Laravel |
|---|---|---|
| Login Required | @login_required |
->middleware('auth') |
| Guest Only | @unauthenticated_user |
->middleware('guest') |
| CSRF Protection | @csrf_protect |
Automatic (can exclude with middleware) |
| Rate Limiting | Custom middleware | ->middleware('throttle:5,1') |
- โ Login with username/email and password
- โ Secure logout
- โ Rate limiting (brute force protection)
- โ Remember me functionality
- โ CSRF protection
- โ Authentication middleware
- โ Protected dashboard
- โ User migration
- โ Database seeders with test data
- โ Responsive templates with Bootstrap
- โ Flexible authentication (username or email)
- โ Flash messages
- โ Error handling and validation
After running php artisan db:seed --class=UserSeeder:
| Username | Password | |
|---|---|---|
admin |
admin@example.com | password123 |
testuser |
testuser@example.com | password123 |
# Laravel # Django
php artisan migrate # python manage.py migrate
php artisan make:model User # Edit models.py manually
php artisan serve # python manage.py runserver
php artisan tinker # python manage.py shell
php artisan make:controller Auth # Create views.py manually// Laravel
$users = User::where('active', true)->get();
$user = User::find(1);
User::create(['name' => 'John']);# Django
users = User.objects.filter(active=True)
user = User.objects.get(id=1)
User.objects.create(name='John'){{-- Laravel Blade --}}
@if(Auth::check())
Welcome, {{ Auth::user()->username }}!
@endif{# Django Templates #}
{% if user.is_authenticated %}
Welcome, {{ user.username }}!
{% endif %}// Laravel
Route::middleware('auth')->group(function () {
Route::get('/dashboard', function () {
return view('dashboard');
});
});# Django
@login_required
def dashboard(request):
return render(request, 'dashboard.html')โโโ app/
โ โโโ Http/
โ โ โโโ Controllers/
โ โ โ โโโ Controller.php # Base controller with shared methods
โ โ โ โโโ AuthController.php # Authentication controller
โ โ โโโ Middleware/
โ โ โโโ Authenticate.php # Authentication middleware
โ โโโ Models/
โ โ โโโ User.php # User model (Eloquent)
โ โโโ Providers/
โ โโโ AppServiceProvider.php # Service provider configuration
โโโ config/ # Configuration files (like Django settings)
โโโ database/
โ โโโ migrations/ # Database migrations
โ โโโ seeders/ # Database seeders
โโโ resources/views/ # Blade templates
โ โโโ layouts/
โ โโโ auth/
โ โโโ dashboard.blade.php
โ โโโ welcome.blade.php
โโโ routes/
โ โโโ web.php # Web routes (like Django urls.py)
โโโ storage/ # File storage and logs
To continue learning, you can implement:
- User Registration (equivalent to Django's register view)
- Password Reset (equivalent to Django's password reset)
- Email Verification (equivalent to Django's email verification)
- User Profile Management (equivalent to Django's user profile)
- REST API (equivalent to Django REST Framework)
- Unit Testing (equivalent to Django's TestCase)
Note: This project is designed exclusively for educational purposes and comparison between Django and Laravel. It is not optimized for production use.