create a modern persian login page with bootstrap 5 for laravel. I want it be…
- User
create a modern persian login page with bootstrap 5 for laravel. I want it be professional and good Ui/Ux.
Assistant
Okay, let's create a modern, professional, and RTL-friendly Persian login page using Bootstrap 5 for your Laravel application.
Key Features:
- RTL Layout:
dir="rtl"and Bootstrap's RTL support. - Persian Text: All labels, placeholders, and buttons in Persian.
- Bootstrap 5 Styling: Modern components like cards, input groups, and responsive design.
- Laravel Blade Syntax: Ready to be used in a
.blade.phpfile. - Error Handling: Placeholders for Laravel's validation errors.
- Font: We'll use a common approach by setting
font-familybut you might want to integrate a specific Persian font like Vazirmatn or IRANSans for the best look.
1. Create the Blade File:
Save this as
resources/views/auth/login.blade.php(or your preferred location).<!DOCTYPE html> <html lang="fa" dir="rtl"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>ورود به حساب کاربری - {{ config('app.name', 'Laravel') }}</title> <!-- Bootstrap CSS --> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous"> <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css" rel="stylesheet"> <!-- Custom Styles --> <style> body { font-family: 'Tahoma', 'Helvetica Neue', Helvetica, Arial, sans-serif; /* Basic fallback, consider a dedicated Persian font */ background-color: #f8f9fa; /* Light gray background */ } .login-container { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 15px; } .login-card { width: 100%; max-width: 450px; /* Max width for the card */ border-radius: 0.75rem; /* Softer corners */ box-shadow: 0 0.5rem 1.5rem rgba(0,0,0,0.1); } .login-card .card-header { background-color: #fff; /* White header */ border-bottom: 0; padding-top: 2rem; padding-bottom: 1rem; text-align: center; } .login-card .card-header img { max-width: 150px; /* Adjust logo size */ margin-bottom: 1rem; } .login-card .card-title { font-weight: 600; color: #333; } .form-control:focus { border-color: #0d6efd; /* Bootstrap primary color */ box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25); } .btn-primary { background-color: #0d6efd; border-color: #0d6efd; padding: 0.75rem 1rem; font-size: 1rem; } .btn-primary:hover { background-color: #0b5ed7; border-color: #0a58ca; } .input-group-text { background-color: #e9ecef; border-right: 0; /* For RTL, left border needs adjustment if icon is on right */ border-left: 1px solid #ced4da; } /* Adjust icon position for RTL */ .input-group .form-control { border-top-left-radius: 0; border-bottom-left-radius: 0; border-top-right-radius: 0.25rem; border-bottom-right-radius: 0.25rem; } .input-group .input-group-text { border-top-right-radius: 0; border-bottom-right-radius: 0; border-top-left-radius: 0.25rem; border-bottom-left-radius: 0.25rem; border-left: 0; border-right: 1px solid #ced4da; } .form-check-input { float: right; margin-left: 0.5em; } .form-check-label { padding-right: 1.7em; /* Space for the checkbox */ } .extra-links a { font-size: 0.9rem; color: #0d6efd; } .extra-links a:hover { text-decoration: underline; } </style> </head> <body> <div class="login-container"> <div class="card login-card"> <div class="card-header"> <!-- Optional: Your Logo --> <!-- <img src="/path/to/your/logo.png" alt="لوگو شرکت"> --> <h4 class="card-title mb-0">ورود به حساب کاربری</h4> </div> <div class="card-body p-4 p-md-5"> <form method="POST" action="{{ route('login') }}"> @csrf <!-- Email Address --> <div class="mb-3"> <label for="email" class="form-label">آدرس ایمیل</label> <div class="input-group"> <span class="input-group-text"><i class="bi bi-envelope-fill"></i></span> <input id="email" type="email" class="form-control @error('email') is-invalid @enderror" name="email" value="{{ old('email') }}" required autocomplete="email" autofocus placeholder="مثال: user@example.com"> </div> @error('email') <div class="invalid-feedback d-block"> <!-- Ensure error is visible --> {{ $message }} </div> @enderror </div> <!-- Password --> <div class="mb-3"> <label for="password" class="form-label">رمز عبور</label> <div class="input-group"> <span class="input-group-text"><i class="bi bi-lock-fill"></i></span> <input id="password" type="password" class="form-control @error('password') is-invalid @enderror" name="password" required autocomplete="current-password" placeholder="رمز عبور خود را وارد کنید"> </div> @error('password') <div class="invalid-feedback d-block"> {{ $message }} </div> @enderror </div> <!-- Remember Me --> <div class="mb-3 form-check"> <input class="form-check-input" type="checkbox" name="remember" id="remember" {{ old('remember') ? 'checked' : '' }}> <label class="form-check-label" for="remember"> مرا به خاطر بسپار </label> </div> <!-- Submit Button --> <div class="d-grid mb-3"> <button type="submit" class="btn btn-primary btn-block fw-bold"> ورود </button> </div> <div class="text-center extra-links"> @if (Route::has('password.request')) <a class="d-block mb-2" href="{{ route('password.request') }}"> رمز عبور خود را فراموش کردهاید؟ </a> @endif @if (Route::has('register')) <a class="d-block" href="{{ route('register') }}"> حساب کاربری ندارید؟ ثبت نام کنید </a> @endif </div> </form> </div> <div class="card-footer text-center py-3"> <small class="text-muted">© {{ date('Y') }} {{ config('app.name', 'Laravel') }}. تمامی حقوق محفوظ است.</small> </div> </div> </div> <!-- Bootstrap JS Bundle --> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script> </body> </html>2. Explanation & Key Changes:
<html lang="fa" dir="rtl">: Sets the language to Persian and direction to Right-to-Left. Bootstrap 5 has excellent RTL support.- Bootstrap CDN: Includes Bootstrap 5 CSS and JS, plus Bootstrap Icons for the input fields.
- Custom CSS (
<style>block):font-family: Basic Tahoma fallback. Strongly recommend using a dedicated Persian web font like 'Vazirmatn' or 'IRANSans' for a truly professional look. You'd typically host these fonts or use a CDN for them.- Example using Vazirmatn (you'd need to set this up):
@font-face { font-family: 'Vazirmatn'; src: url('/fonts/Vazirmatn-Regular.woff2') format('woff2'); /* Adjust path */ font-weight: normal; font-style: normal; } body { font-family: 'Vazirmatn', Tahoma, sans-serif; background-color: #f8f9fa; }
- Example using Vazirmatn (you'd need to set this up):
.login-container: Full viewport height, flex centered..login-card: Styled card with max-width, rounded corners, and shadow..card-header: Centered text, space for a logo.- Input Group Icon Styling: Adjusted for RTL so the icon appears on the right side of the input field correctly.
.form-check-inputand.form-check-label: Styled for RTL checkbox alignment..extra-links: Styling for "Forgot Password" and "Register" links.
- Persian Text: All user-facing text is translated to Persian.
- Logo Placeholder: Commented out
<img>tag for your logo. - Input Groups: Uses Bootstrap's
input-groupwithinput-group-textto add icons (email and lock) to the input fields for better UX. - Error Messages:
@error('email') is-invalid @enderroradds Bootstrap's validation styling.- The error message itself is displayed below the input using
d-blockto ensure it's always visible when present (Bootstrap's defaultinvalid-feedbackmight be hidden until focus/interaction).
- Laravel Blade Directives:
{{ config('app.name', 'Laravel') }}: Displays your application name.{{ route('login') }},{{ route('password.request') }},{{ route('register') }}: Laravel route helpers.@csrf: CSRF protection.{{ old('email') }},{{ old('remember') }}: Repopulates form fields on validation error.@error('field') ... @enderror: Displays validation errors.
- Responsive Design: The card (
max-width: 450px) and Bootstrap's grid system ensure it looks good on various screen sizes. - Footer: A simple copyright footer.
3. How to Use:
- Make sure you have a Laravel project set up with authentication scaffolding (e.g., using Laravel Breeze or Jetstream, or manually setting up routes and controllers).
- Place the code above into
resources/views/auth/login.blade.php. - Define the routes in
routes/web.phpif they aren't already (Laravel's auth scaffolding usually does this):use App\Http\Controllers\Auth\AuthenticatedSessionController; Route::get('login', [AuthenticatedSessionController::class, 'create']) ->middleware('guest') ->name('login'); Route::post('login', [AuthenticatedSessionController::class, 'store']) ->middleware('guest'); // Potentially also password.request and register routes - If you want to use a specific Persian font:
- Download the font files (e.g., WOFF2 format).
- Place them in your
public/fontsdirectory. - Update the
@font-facerule in the<style>section with the correct path.
- Replace the placeholder logo comment with your actual logo if you have one.
This setup provides a professional, modern, and user-friendly Persian login page for your Laravel application. Remember to test it on different devices and browsers.
- RTL Layout:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.