A Simple Blogging System built with Laravel
A Simple Blogging System built with Laravel
Prerequisites
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=blog_system
DB_USERNAME=root
DB_PASSWORD=yourpassword
Then run:
use App\Http\Controllers\PostController;
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Post;
Post::create($request->all());
return redirect()->route('posts.index')->with('success', 'Post
created successfully.');
}
$post->update($request->all());
return redirect()->route('posts.index')->with('success', 'Post
updated successfully.');
}
1. Layout (layout.blade.php)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Simple Blog</title>
<link rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.c
ss">
</head>
<body>
<div class="container mt-4">
@yield('content')
</div>
</body>
</html>
@section('content')
<h2>Blog Posts</h2>
<a href="{{ route('posts.create') }}" class="btn btn-primary mb-3">Create
Post</a>
@if(session('success'))
<div class="alert alert-success">{{ session('success') }}</div>
@endif
<table class="table">
<tr>
<th>Title</th>
<th>Actions</th>
</tr>
@foreach ($posts as $post)
<tr>
<td>{{ $post->title }}</td>
<td>
<a href="{{ route('posts.show', $post) }}" class="btn btn-info
btn-sm">View</a>
<a href="{{ route('posts.edit', $post) }}" class="btn btn-
warning btn-sm">Edit</a>
<form action="{{ route('posts.destroy', $post) }}"
method="POST" style="display:inline;">
@csrf @method('DELETE')
<button type="submit" class="btn btn-danger btn-
sm">Delete</button>
</form>
</td>
</tr>
@endforeach
</table>
@endsection
@section('content')
<h2>Create Post</h2>
@if ($errors->any())
<div class="alert alert-danger">
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
@section('content')
<h2>Edit Post</h2>
@section('content')
<h2>{{ $post->title }}</h2>
<p>{{ $post->description }}</p>
<a href="{{ route('posts.index') }}" class="btn btn-secondary">Back</a>
@endsection
Features Implemented
CRUD operations (Create, Read, Update, Delete)
Basic form validation
Laravel Blade templating with Bootstrap styling
Flash messages for user feedback
This is a simple yet fully functional Laravel blogging system. Let me know if you need
additional features like authentication, image uploads, or comments!