소스 검색

Some fixes, added scheduler

AItEKS 5 일 전
부모
커밋
d1cd3b6ef9

+ 11 - 0
app/Console/Commands/PublishScheduledPosts.php

@@ -4,6 +4,8 @@ namespace App\Console\Commands;
 
 use Illuminate\Console\Command;
 
+use App\Models\Post;
+
 class PublishScheduledPosts extends Command
 {
     /**
@@ -26,5 +28,14 @@ class PublishScheduledPosts extends Command
     public function handle()
     {
         //
+        $count = Post::where('is_published', false)
+        ->whereNotNull('scheduled_at')
+        ->where('scheduled_at', '<=', now())
+        ->update([
+            'is_published' => true, 
+            'published_at' => now()
+        ]);
+
+        $this->info("Опубликовано статей: " . $count);
     }
 }

+ 1 - 3
resources/views/admin/comments/index.blade.php

@@ -29,14 +29,12 @@
                             </a>
                         </td>
                         <td class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium space-x-2">
-                            <!-- Кнопка Одобрить -->
                             <form action="{{ route('admin.comments.approve', $comment) }}" method="POST" class="inline-block">
                                 @csrf
                                 @method('PATCH')
                                 <button type="submit" class="text-green-600 hover:text-green-900 font-bold">Одобрить</button>
                             </form>
 
-                            <!-- Кнопка Удалить -->
                             <form action="{{ route('admin.comments.destroy', $comment) }}" method="POST" class="inline-block" onsubmit="return confirm('Удалить этот спам?');">
                                 @csrf
                                 @method('DELETE')
@@ -47,7 +45,7 @@
                 @empty
                     <tr>
                         <td colspan="4" class="px-6 py-10 text-center text-gray-500">
-                            Нет комментариев, ожидающих проверки. Все чисто! 🎉
+                            Нет комментариев, ожидающих проверки. Все чисто!
                         </td>
                     </tr>
                 @endforelse

+ 0 - 3
resources/views/admin/posts/form.blade.php

@@ -9,19 +9,16 @@
             @if(isset($post)) @method('PUT') @endif
 
             <div class="space-y-6">
-                <!-- Заголовок -->
                 <div>
                     <label class="block text-sm font-medium text-gray-700">Заголовок</label>
                     <input type="text" name="title" value="{{ old('title', $post->title ?? '') }}" class="mt-1 block w-full rounded-md border border-gray-300 p-2 shadow-sm focus:border-indigo-500 focus:ring-indigo-500">
                 </div>
 
-                <!-- Контент -->
                 <div>
                     <label class="block text-sm font-medium text-gray-700">Текст статьи</label>
                     <textarea name="content" rows="10" class="mt-1 block w-full rounded-md border border-gray-300 p-2 shadow-sm focus:border-indigo-500 focus:ring-indigo-500">{{ old('content', $post->content ?? '') }}</textarea>
                 </div>
 
-                <!-- Настройки публикации -->
                 <div class="grid grid-cols-1 md:grid-cols-2 gap-6 bg-gray-50 p-4 rounded-md">
                     <div>
                         <label class="block text-sm font-medium text-gray-700">Запланировать публикацию (дата/время)</label>

+ 0 - 1
resources/views/admin/posts/index.blade.php

@@ -61,7 +61,6 @@
             </table>
         </div>
 
-        <!-- Пагинация -->
         <div class="mt-4">
             {{ $posts->links() }}
         </div>

+ 18 - 12
resources/views/layout.blade.php

@@ -4,9 +4,7 @@
     <meta charset="UTF-8">
     <meta name="viewport" content="width=device-width, initial-scale=1.0">
     <title>My Simple Blog</title>
-    <!-- Подключаем Tailwind CSS -->
     <script src="https://cdn.tailwindcss.com"></script>
-    <!-- Шрифт Inter для красоты -->
     <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;600;700&display=swap" rel="stylesheet">
     <style>
         body { font-family: 'Inter', sans-serif; }
@@ -14,7 +12,6 @@
 </head>
 <body class="bg-gray-50 text-gray-800 flex flex-col min-h-screen">
 
-    <!-- Навигация -->
     <nav class="bg-white shadow-sm border-b border-gray-100">
         <div class="max-w-4xl mx-auto px-4 sm:px-6 lg:px-8">
             <div class="flex justify-between h-16">
@@ -23,28 +20,38 @@
                         BlogApp
                     </a>
                 </div>
-                <div class="flex items-center space-x-4">
-                    <!-- Просто ссылка на админку. Если нажать - браузер попросит пароль -->
-                    <a href="{{ route('admin.posts.index') }}" class="text-sm text-indigo-600 hover:text-indigo-800 font-bold">
-                        Панель администратора
+                
+                <div class="flex items-center space-x-6">
+                    <a href="{{ route('admin.posts.index') }}" class="text-sm text-gray-600 hover:text-indigo-600 font-medium transition">
+                        Управление статьями
+                    </a>
+
+                    <a href="{{ route('admin.comments.index') }}" class="text-sm text-gray-600 hover:text-indigo-600 font-medium transition flex items-center">
+                        Модерация
+                        @php
+                            $pendingCount = \App\Models\Comment::where('is_approved', false)->count();
+                        @endphp
+                        @if($pendingCount > 0)
+                            <span class="ml-2 bg-red-100 text-red-600 text-xs font-bold px-2 py-0.5 rounded-full border border-red-200">
+                                {{ $pendingCount }}
+                            </span>
+                        @endif
                     </a>
                 </div>
             </div>
         </div>
     </nav>
 
-    <!-- Основной контент -->
     <main class="flex-grow">
         <div class="max-w-4xl mx-auto py-10 px-4 sm:px-6 lg:px-8">
-            <!-- Сообщения об успехе -->
             @if(session('success'))
-                <div class="mb-6 bg-green-50 border-l-4 border-green-400 p-4">
+                <div class="mb-6 bg-green-50 border-l-4 border-green-400 p-4 rounded-md shadow-sm">
                     <div class="flex">
                         <div class="flex-shrink-0">
                             <svg class="h-5 w-5 text-green-400" fill="currentColor" viewBox="0 0 20 20"><path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z" clip-rule="evenodd"/></svg>
                         </div>
                         <div class="ml-3">
-                            <p class="text-sm text-green-700">{{ session('success') }}</p>
+                            <p class="text-sm text-green-700 font-medium">{{ session('success') }}</p>
                         </div>
                     </div>
                 </div>
@@ -54,7 +61,6 @@
         </div>
     </main>
 
-    <!-- Футер -->
     <footer class="bg-white border-t border-gray-200 mt-12">
         <div class="max-w-4xl mx-auto py-6 px-4 overflow-hidden sm:px-6 lg:px-8">
             <p class="text-center text-base text-gray-400">

+ 0 - 1
resources/views/posts/index.blade.php

@@ -32,7 +32,6 @@
             @endforelse
         </div>
 
-        <!-- Пагинация -->
         <div class="mt-8">
             {{ $posts->links() }}
         </div>

+ 0 - 4
resources/views/posts/show.blade.php

@@ -13,11 +13,9 @@
             {!! nl2br(e($post->content)) !!}
         </div>
 
-        <!-- Секция комментариев -->
         <div class="border-t pt-10">
             <h3 class="text-2xl font-bold text-gray-900 mb-6">Комментарии ({{ $post->comments->where('is_approved', true)->count() }})</h3>
 
-            <!-- Форма добавления -->
             <div class="mb-10 bg-gray-50 p-6 rounded-lg">
                 <h4 class="text-lg font-medium mb-4">Оставить комментарий</h4>
                 <form action="{{ route('comments.store', $post) }}" method="POST">
@@ -36,7 +34,6 @@
                 </form>
             </div>
 
-            <!-- Список комментариев -->
             <div class="space-y-6">
                 @foreach($post->comments as $comment)
                     @if($comment->is_approved)
@@ -56,7 +53,6 @@
                         </div>
                     @else
                         @auth
-                            <!-- Админ видит неодобренные комменты -->
                             <div class="flex space-x-4 opacity-50 border-l-2 border-yellow-400 pl-4">
                                 <div>
                                     <div class="text-sm font-bold text-gray-900">{{ $comment->author_name }} (На модерации)</div>

+ 3 - 0
routes/console.php

@@ -2,7 +2,10 @@
 
 use Illuminate\Foundation\Inspiring;
 use Illuminate\Support\Facades\Artisan;
+use Illuminate\Support\Facades\Schedule;
 
 Artisan::command('inspire', function () {
     $this->comment(Inspiring::quote());
 })->purpose('Display an inspiring quote');
+
+Schedule::command('blog:publish-scheduled')->everyMinute();

+ 1 - 1
routes/web.php

@@ -8,7 +8,7 @@ use App\Http\Controllers\Admin\CommentController as AdminCommentController;
 
 Route::get('/', [PostController::class, 'index'])->name('home');
 Route::get('/posts/{post}', [PostController::class, 'show'])->name('posts.show');
-Route::post('/posts/{post}/comments', [CommentController::class, 'comments.store']);
+Route::post('/posts/{post}/comments', [CommentController::class, 'store'])->name('comments.store');
 
 Route::middleware(['auth.basic'])->prefix('admin')->name('admin.')->group(function () {
     Route::resource('posts', AdminPostController::class);