Laravel 12 Blog System Tutorial: In this guide, we will build a complete blog system from scratch using Laravel 12. This project includes CRUD operations, image upload, and a simple admin panel.
This type of project is widely used in real-world applications such as CMS, news websites, and personal blogs.
Step 1. Install Laravel 12
composer create-project laravel/laravel blog-system cd blog-system
Step 2. Setup Database
DB_DATABASE=blog_system DB_USERNAME=root DB_PASSWORD=
php artisan migrate
Step 3. Create Model & Migration
php artisan make:model Post -m
Schema::create('posts', function (Blueprint $table) {
$table->id();
$table->string('title');
$table->string('slug')->unique();
$table->text('description');
$table->string('image')->nullable();
$table->timestamps();
});
php artisan migrate
Step 4. Create Controller
php artisan make:controller PostController
class PostController extends Controller
{
public function index() {
return view('posts.index', ['posts' => Post::latest()->get()]);
}
public function create() {
return view('posts.create');
}
public function store(Request $request) {
$data = $request->validate([
'title' => 'required',
'description' => 'required',
'image' => 'image|mimes:jpg,png,jpeg|max:2048'
]);
if ($request->hasFile('image')) {
$data['image'] = $request->file('image')->store('posts', 'public');
}
$data['slug'] = \Str::slug($request->title);
Post::create($data);
return redirect()->route('posts.index');
}
public function edit(Post $post) {
return view('posts.edit', compact('post'));
}
public function update(Request $request, Post $post) {
$post->update($request->all());
return redirect()->route('posts.index');
}
public function destroy(Post $post) {
$post->delete();
return back();
}
}
Step 5. Add Fillable
protected $fillable = ['title', 'slug', 'description', 'image'];
Step 6. Create Routes
use App\Http\Controllers\PostController;
Route::resource('posts', PostController::class);
Step 7. Create Blade Views
Create simple views:
- posts/index.blade.php
- posts/create.blade.php
- posts/edit.blade.php
Example form:
<form method="POST" enctype="multipart/form-data"> @csrf <input type="text" name="title"> <textarea name="description"></textarea> <input type="file" name="image"> <button type="submit">Save</button> </form>
Conclusion: You have successfully built a complete blog system in Laravel 12 with CRUD functionality, image upload, and admin structure. This is a real-world project that helps you understand Laravel deeply.
We always thanks to you for reading our blogs.
Dharmesh Chauhan
(Swapinfoway Founder)Hello Sir, We are brothers origin from Gujarat India, Fullstack developers working together since 2016. We have lots of skills in web development in different technologies here I mention PHP, Laravel, Javascript, Vuejs, Ajax, API, Payment Gateway Integration, Database, HTML5, CSS3, and Server Administration. So you need our service Please Contact Us
Haresh Chauhan
(Co-Founder)We Are Also Recommending You :
- Laravel 6 Cron Job Task Scheduling Tutorial
- Force Redirect to www From Non-www Using htaccess In Laravel
- How to Install Laravel 10 With Video Tutorial
- Filtering data excel export in laravel example
- MongoDB Database Connection In Laravel
- Laravel 9 File manager integration tutorial
- HTTP Client Guzzle Package With Basic Usage In Laravel
- Laravel Scope With Example Usage
- How to Generate PDF File Using DomPDF In Laravel 9 Example
- Laravel 10 Firebase Web Push Notification Tutorial