Simple Blade Template Laravel
April 5, 2025 · AI Conversations
—
### ✅ 1. **Create Route**
In your `routes/web.php` file:
use IlluminateSupportFacadesRoute;
Route::get('/', function () {
return view('welcome'); // or 'home' if you're creating a new view
});
—
### ✅ 2. **Create Blade View**
Create a new Blade file in `resources/views/`.
Example: `resources/views/welcome.blade.php`
<!DOCTYPE html>
<html>
<head>
<title>Welcome Page</title>
</head>
<body>
<h1>Hello from Laravel 12 Blade!</h1>
</body>
</html>
You can also pass data to this view like:
Route::get('/', function () {
return view('welcome', ['name' => 'Neeraj']);
});
Then in the Blade view:
<h1>Hello, {{ $name }}!</h1>
—
### ✅ 3. **Use Blade Layouts (Optional but Common)**
If you want to use layout:
#### `resources/views/layouts/app.blade.php`
<!DOCTYPE html>
<html>
<head>
<title>@yield('title')</title>
</head>
<body>
<div class="container">
@yield('content')
</div>
</body>
</html>
#### `resources/views/home.blade.php`
@extends('layouts.app')
@section('title', 'Home Page')
@section('content')
<h1>Welcome to Home Page</h1>
@endsection
And route:
Route::get('/home', fn() => view('home'));
—
Let me know if you want to include Vue, Inertia, or Tailwind with this setup too.
—
## ✅ Step-by-Step: Laravel 12 with Blade Auth (Login/Register)
### 1. **Install Laravel 12**
composer create-project laravel/laravel:^12 laravel-blade-auth
cd laravel-blade-auth
—
### 2. **Install Laravel Breeze (Blade Version)**
composer require laravel/breeze --dev
Then install **Blade scaffolding**:
php artisan breeze:install blade
—
### 3. **Run Migrations**
First, set up your database in `.env`, then:
php artisan migrate
—
### 4. **Install Dependencies and Build Assets**
npm install && npm run build
If you're using **Yarn** instead:
yarn && yarn build
—
### 5. **Serve the Application**
php artisan serve
Now visit `http://localhost:8000` – You’ll see the Laravel welcome page with **Login** and **Register** links already set up.
—
## 🧪 What’s Included
This will generate:
– Blade views for login, register, password reset, email verification.
– Auth controllers and routes in `routes/web.php`.
– Middleware-protected dashboard page.
—
## 🔐 Access Auth Pages
– `/login`
– `/register`
– `/dashboard` (after login)
—
Let me know if you want to use Bootstrap or Tailwind in the Blade views, or if you want to customize the auth flow.