blogs
This commit is contained in:
71
resources/views/blogs/create.blade.php
Normal file
71
resources/views/blogs/create.blade.php
Normal file
@ -0,0 +1,71 @@
|
||||
@extends('layouts.app')
|
||||
|
||||
@section('content')
|
||||
<div class="container">
|
||||
<h1>Add Blog</h1>
|
||||
<form action="{{ route('blogs.store') }}" method="POST" enctype="multipart/form-data">
|
||||
@csrf
|
||||
|
||||
<div class="form-group mb-3">
|
||||
<label for="title">Title</label>
|
||||
<input type="text" name="title" class="form-control">
|
||||
</div>
|
||||
<div class="form-group mb-3">
|
||||
<label for="thumbnail">thumbnail</label>
|
||||
<input type="file" name="thumbnail" class="form-control">
|
||||
</div>
|
||||
<div class="form-group mb-3">
|
||||
<label for="banner">Banner</label>
|
||||
<input type="file" name="banner" class="form-control">
|
||||
</div>
|
||||
|
||||
<div class="form-group mb-3">
|
||||
<label for="subtitle1">Subtitle 1</label>
|
||||
<input type="text" name="subtitle1" class="form-control">
|
||||
</div>
|
||||
|
||||
<div class="form-group mb-3">
|
||||
<label for="description1">Description 1</label>
|
||||
<textarea name="description1" rows="4" class="form-control"></textarea>
|
||||
</div>
|
||||
|
||||
<div class="form-group mb-3">
|
||||
<label for="subtitle2">Subtitle 2</label>
|
||||
<input type="text" name="subtitle2" class="form-control">
|
||||
</div>
|
||||
|
||||
<div class="form-group mb-3">
|
||||
<label for="description2">Description 2</label>
|
||||
<textarea name="description2" rows="4" class="form-control"></textarea>
|
||||
</div>
|
||||
|
||||
<div class="form-group mb-3">
|
||||
<label for="image">Image</label>
|
||||
<input type="file" name="image" class="form-control">
|
||||
</div>
|
||||
|
||||
<div class="form-group mb-3">
|
||||
<label for="button_text">Button Text</label>
|
||||
<input type="text" name="button_text" class="form-control">
|
||||
</div>
|
||||
|
||||
<div class="form-group mb-3">
|
||||
<label for="button_url">Button URL</label>
|
||||
<input type="text" name="button_url" class="form-control">
|
||||
</div>
|
||||
|
||||
<div class="form-group mb-3">
|
||||
<label for="display_order">Display Order</label>
|
||||
<input type="number" name="display_order" class="form-control">
|
||||
</div>
|
||||
|
||||
<div class="form-check mb-3">
|
||||
<input type="checkbox" name="is_published" id="is_published" class="form-check-input" value="1" {{ old('is_published') ? 'checked' : '' }}>
|
||||
<label class="form-check-label" for="is_published">Publish</label>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-success">Save</button>
|
||||
<a href="{{ route('blogs.index') }}" class="btn btn-secondary">Cancel</a>
|
||||
</form>
|
||||
</div>
|
||||
@endsection
|
87
resources/views/blogs/edit.blade.php
Normal file
87
resources/views/blogs/edit.blade.php
Normal file
@ -0,0 +1,87 @@
|
||||
@extends('layouts.app')
|
||||
|
||||
@section('content')
|
||||
<div class="container">
|
||||
<h1>Edit Blog</h1>
|
||||
<form method="POST" action="{{ route('blogs.update', $blog->id) }}" enctype="multipart/form-data">
|
||||
@csrf
|
||||
@method('PUT')
|
||||
|
||||
<div class="form-group mb-3">
|
||||
<label for="title" class="form-label">Title</label>
|
||||
<input type="text" name="title" class="form-control" value="{{ old('title', $blog->title) }}">
|
||||
</div>
|
||||
|
||||
<div class="form-group mb-3">
|
||||
<label for="thumbnail" class="form-label">Thumbnail</label>
|
||||
<input type="file" name="thumbnail" class="form-control">
|
||||
@if ($blog->thumbnail)
|
||||
<p>Current thumbnail:</p>
|
||||
<img src="{{ asset('storage/' . $blog->thumbnail) }}" width="150">
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<div class="form-group mb-3">
|
||||
<label for="banner" class="form-label">Banner</label>
|
||||
<input type="file" name="banner" class="form-control">
|
||||
@if ($blog->banner)
|
||||
<p>Current banner:</p>
|
||||
<img src="{{ asset('storage/' . $blog->banner) }}" width="150">
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<div class="form-group mb-3">
|
||||
<label for="subtitle1" class="form-label">Subtitle 1</label>
|
||||
<input type="text" name="subtitle1" class="form-control" value="{{ old('subtitle1', $blog->subtitle1) }}">
|
||||
</div>
|
||||
|
||||
<div class="form-group mb-3">
|
||||
<label for="description1" class="form-label">Description 1</label>
|
||||
<textarea name="description1" class="form-control" rows="4">{{ old('description1', $blog->description1) }}</textarea>
|
||||
</div>
|
||||
|
||||
<div class="form-group mb-3">
|
||||
<label for="subtitle2" class="form-label">Subtitle 2</label>
|
||||
<input type="text" name="subtitle2" class="form-control" value="{{ old('subtitle2', $blog->subtitle2) }}">
|
||||
</div>
|
||||
|
||||
<div class="form-group mb-3">
|
||||
<label for="description2" class="form-label">Description 2</label>
|
||||
<textarea name="description2" class="form-control" rows="4">{{ old('description2', $blog->description2) }}</textarea>
|
||||
</div>
|
||||
|
||||
<div class="form-group mb-3">
|
||||
<label for="image" class="form-label">Image</label>
|
||||
<input type="file" name="image" class="form-control">
|
||||
@if ($blog->image)
|
||||
<p>Current image:</p>
|
||||
<img src="{{ asset('storage/' . $blog->image) }}" width="150">
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<div class="form-group mb-3">
|
||||
<label for="button_text" class="form-label">Button Text</label>
|
||||
<input type="text" name="button_text" class="form-control" value="{{ old('button_text', $blog->button_text) }}">
|
||||
</div>
|
||||
|
||||
<div class="form-group mb-3">
|
||||
<label for="button_url" class="form-label">Button URL</label>
|
||||
<input type="text" name="button_url" class="form-control" value="{{ old('button_url', $blog->button_url) }}">
|
||||
</div>
|
||||
|
||||
<div class="form-group mb-3">
|
||||
<label for="display_order" class="form-label">Display Order</label>
|
||||
<input type="number" name="display_order" class="form-control" value="{{ old('display_order', $blog->display_order) }}">
|
||||
</div>
|
||||
|
||||
<div class="form-check mb-3">
|
||||
<input type="checkbox" name="is_published" id="is_published" class="form-check-input" value="1"
|
||||
{{ old('is_published', $blog->is_published) ? 'checked' : '' }}>
|
||||
<label class="form-check-label" for="is_published">Publish</label>
|
||||
</div>
|
||||
|
||||
<button class="btn btn-success">Update</button>
|
||||
<a href="{{ route('blogs.index') }}" class="btn btn-danger">Cancel</a>
|
||||
</form>
|
||||
</div>
|
||||
@endsection
|
142
resources/views/blogs/index.blade.php
Normal file
142
resources/views/blogs/index.blade.php
Normal file
@ -0,0 +1,142 @@
|
||||
@extends('layouts.app')
|
||||
|
||||
@section('content')
|
||||
<div class="container">
|
||||
<h1>Blogs</h1>
|
||||
|
||||
<a href="{{ route('blogs.create') }}" class="btn btn-primary mb-3">Create New Blog</a>
|
||||
|
||||
@if(session('success'))
|
||||
<div class="alert alert-success">{{ session('success') }}</div>
|
||||
@endif
|
||||
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Title</th>
|
||||
<th>Thumbnail</th>
|
||||
<th>Button Text</th>
|
||||
<th>Button URL</th>
|
||||
<th>Display Order</th>
|
||||
<th>Publish</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@forelse($blogs as $blog)
|
||||
<tr data-id="{{ $blog->id }}">
|
||||
<td>{{ $blog->title }}</td>
|
||||
<td>
|
||||
@if($blog->thumbnail)
|
||||
<img src="{{ asset('storage/' . $blog->thumbnail) }}" alt="bg-img" width="100">
|
||||
@else
|
||||
N/A
|
||||
@endif
|
||||
</td>
|
||||
<td>{{ $blog->button_text }}</td>
|
||||
<td>{{ $blog->button_url }}</td>
|
||||
<td>{{ $blog->display_order }}</td>
|
||||
<td>
|
||||
<div class="form-check form-switch">
|
||||
<input type="checkbox"
|
||||
class="form-check-input publish-toggle"
|
||||
data-id="{{ $blog->id }}"
|
||||
{{ $blog->is_published ? 'checked' : '' }}>
|
||||
</div>
|
||||
|
||||
|
||||
</td>
|
||||
|
||||
<td>
|
||||
<a href="{{ route('blogs.show', $blog->id) }}" class="btn btn-sm btn-info">View</a>
|
||||
<a href="{{ route('blogs.edit', $blog->id) }}" class="btn btn-sm btn-warning">Edit</a>
|
||||
<form action="{{ route('blogs.destroy', $blog->id) }}" method="POST" style="display:inline-block">
|
||||
@csrf @method('DELETE')
|
||||
<button class="btn btn-sm btn-danger" onclick="return confirm('Delete this blog?')">Delete</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
@empty
|
||||
<tr><td colspan="7">No blogs found.</td></tr>
|
||||
@endforelse
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
|
||||
@section('scripts')
|
||||
<script src="https://cdn.jsdelivr.net/npm/sortablejs@1.15.0/Sortable.min.js"></script>
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
const tableBody = document.querySelector("tbody");
|
||||
|
||||
if (tableBody) {
|
||||
new Sortable(tableBody, {
|
||||
animation: 150,
|
||||
onEnd: function () {
|
||||
const order = [];
|
||||
document.querySelectorAll("tbody tr").forEach((row, index) => {
|
||||
order.push({
|
||||
id: row.dataset.id,
|
||||
display_order: index + 1
|
||||
});
|
||||
});
|
||||
|
||||
fetch("{{ route('blogs.updateOrder') }}", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"X-CSRF-TOKEN": "{{ csrf_token() }}",
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body: JSON.stringify({ order: order })
|
||||
})
|
||||
.then(res => res.json())
|
||||
.then(data => {
|
||||
console.log(data);
|
||||
})
|
||||
.catch(err => console.error('Update failed', err));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
</script>
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
// Existing sortable code...
|
||||
|
||||
// New AJAX publish toggle
|
||||
document.querySelectorAll('.publish-toggle').forEach((checkbox) => {
|
||||
checkbox.addEventListener('change', function () {
|
||||
const blogId = this.dataset.id;
|
||||
const isPublished = this.checked ? 1 : 0;
|
||||
|
||||
fetch(`/blogs/${blogId}/toggle-publish`, {
|
||||
method: 'PATCH',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRF-TOKEN': '{{ csrf_token() }}'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
is_published: isPublished,
|
||||
})
|
||||
})
|
||||
.then(response => {
|
||||
if (!response.ok) throw new Error("Failed to update");
|
||||
return response.json();
|
||||
})
|
||||
.then(data => {
|
||||
console.log("Publish status updated:", data);
|
||||
})
|
||||
.catch(async err => {
|
||||
const errorText = await err?.response?.text?.();
|
||||
console.error("Server error:", errorText);
|
||||
alert("Error updating publish status.");
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
@endsection
|
69
resources/views/blogs/show.blade.php
Normal file
69
resources/views/blogs/show.blade.php
Normal file
@ -0,0 +1,69 @@
|
||||
@extends('layouts.app')
|
||||
|
||||
@section('content')
|
||||
<div class="container">
|
||||
<h1>Blog Details</h1>
|
||||
|
||||
<ul class="list-group mb-4">
|
||||
<li class="list-group-item"><strong>Title:</strong> {{ $blog->title }}</li>
|
||||
|
||||
<li class="list-group-item">
|
||||
<strong>Thumbnail:</strong>
|
||||
@if($blog->thumbnail)
|
||||
<div class="mt-2">
|
||||
<img src="{{ Storage::url($blog->thumbnail) }}" alt="Thumbnail" width="200">
|
||||
</div>
|
||||
@else
|
||||
N/A
|
||||
@endif
|
||||
</li>
|
||||
|
||||
<li class="list-group-item">
|
||||
<strong>Banner:</strong>
|
||||
@if($blog->banner)
|
||||
<div class="mt-2">
|
||||
<img src="{{ Storage::url($blog->banner) }}" alt="Banner" width="200">
|
||||
</div>
|
||||
@else
|
||||
N/A
|
||||
@endif
|
||||
</li>
|
||||
|
||||
<li class="list-group-item"><strong>Subtitle 1:</strong> {{ $blog->subtitle1 ?? 'N/A' }}</li>
|
||||
|
||||
<li class="list-group-item">
|
||||
<strong>Description 1:</strong><br>
|
||||
<div class="mt-2">{{ $blog->description1 ?? 'N/A' }}</div>
|
||||
</li>
|
||||
|
||||
<li class="list-group-item"><strong>Subtitle 2:</strong> {{ $blog->subtitle2 ?? 'N/A' }}</li>
|
||||
|
||||
<li class="list-group-item">
|
||||
<strong>Description 2:</strong><br>
|
||||
<div class="mt-2">{{ $blog->description2 ?? 'N/A' }}</div>
|
||||
</li>
|
||||
|
||||
<li class="list-group-item">
|
||||
<strong>Image:</strong>
|
||||
@if($blog->image)
|
||||
<div class="mt-2">
|
||||
<img src="{{ Storage::url($blog->image) }}" alt="Image" width="200">
|
||||
</div>
|
||||
@else
|
||||
N/A
|
||||
@endif
|
||||
</li>
|
||||
|
||||
<li class="list-group-item"><strong>Button Text:</strong> {{ $blog->button_text }}</li>
|
||||
<li class="list-group-item"><strong>Button URL:</strong> {{ $blog->button_url ?? 'N/A' }}</li>
|
||||
<li class="list-group-item"><strong>Display Order:</strong> {{ $blog->display_order ?? 'N/A' }}</li>
|
||||
<li class="list-group-item"><strong>Published:</strong> {{ $blog->is_published ? 'Yes' : 'No' }}</li>
|
||||
|
||||
<li class="list-group-item"><strong>Created At:</strong> {{ $blog->created_at->format('Y-m-d H:i') }}</li>
|
||||
<li class="list-group-item"><strong>Updated At:</strong> {{ $blog->updated_at->format('Y-m-d H:i') }}</li>
|
||||
</ul>
|
||||
|
||||
<a href="{{ route('blogs.edit', $blog->id) }}" class="btn btn-warning">Edit</a>
|
||||
<a href="{{ route('blogs.index') }}" class="btn btn-secondary mt-3">Back to List</a>
|
||||
</div>
|
||||
@endsection
|
Reference in New Issue
Block a user