NewsPortal Pro / Documentation

Overview

NewsPortal Pro is a full-featured, production-ready news magazine application built on Laravel 12, PHP 8.2, and Bootstrap 5.3. It provides everything a professional publication needs out of the box โ€” editorial workflows, AI enrichment, comment moderation, newsletter management, and a beautiful responsive frontend.

๐Ÿ“ฐ
30 Articles
Seeded & ready
๐Ÿ‘ฅ
17 Users
4 roles
๐Ÿค–
6 AI Features
Each toggleable
๐ŸŽจ
12 Categories
Custom colors

NewsPortal Pro ships with one-command setup scripts โ€” setup.bat for Windows and setup.sh for Linux/Mac. These handle everything automatically. See the Setup Guide for step-by-step instructions.

Requirements

RequirementVersionNotesStatus
PHP8.2+Required extensions: pdo_mysql, mbstring, xml, gd, zip, bcmath, curlRequired
Composer2.xPHP dependency managerRequired
MySQL8.0+MariaDB 10.4+ also supportedRequired
Laravel12.xInstalled via ComposerRequired
OpenAI API KeyAnyOnly needed for AI featuresOptional
SMTP ServerAnyGmail, Mailtrap, Mailgun etc.Optional

Recommended Windows Environments

  • Laragon โ€” Best option. Includes PHP 8.2, MySQL 8, Composer in one installer. laragon.org
  • XAMPP โ€” Use the PHP 8.2 version. apachefriends.org
  • Laravel Herd โ€” Laravel's official local environment. herd.laravel.com

Installation

Option A โ€” One-Command Setup (Recommended)

# Windows โ€” double-click or run in Command Prompt
> setup.bat

# Linux / macOS
$ chmod +x setup.sh && ./setup.sh

The script will prompt you for database credentials, create the database automatically, install all dependencies, run migrations, and seed demo data.

Option B โ€” Manual Steps

# 1. Install dependencies
$ composer install

# 2. Copy environment file
$ cp .env.example .env

# 3. Generate application key
$ php artisan key:generate

# 4. Edit .env with your DB credentials (see below)

# 5. Create database in MySQL
mysql> CREATE DATABASE news_portal CHARACTER SET utf8mb4;

# 6. Run migrations + seed demo data
$ php artisan migrate --seed

# 7. Start the development server
$ php artisan serve
   INFO  Server running on http://127.0.0.1:8000

After setup: Frontend โ†’ http://localhost:8000 ยท Admin โ†’ http://localhost:8000/admin ยท Login: admin@example.com / password

File Structure

newsportal/ โ”œโ”€โ”€ app/ โ”‚ โ”œโ”€โ”€ Http/Controllers/ โ”‚ โ”‚ โ”œโ”€โ”€ Admin/ # Dashboard, Articles, Categories, Comments, Users, Settings โ”‚ โ”‚ โ”œโ”€โ”€ Auth/ # Login, Register, Logout โ”‚ โ”‚ โ””โ”€โ”€ Frontend/ # Home, Article, Category, Search, Newsletter โ”‚ โ”œโ”€โ”€ Http/Middleware/ โ”‚ โ”‚ โ”œโ”€โ”€ IsAdmin.php # admin + editor access โ”‚ โ”‚ โ”œโ”€โ”€ IsAdminOnly.php # admin only (Users, Settings) โ”‚ โ”‚ โ””โ”€โ”€ ApplyMailSettings.php # loads SMTP from DB at runtime โ”‚ โ”œโ”€โ”€ Models/ โ”‚ โ”‚ โ”œโ”€โ”€ Article.php # SoftDeletes, AI fields, image_url accessor โ”‚ โ”‚ โ”œโ”€โ”€ Category.php # color, parent, slug auto-generation โ”‚ โ”‚ โ”œโ”€โ”€ Comment.php # threaded, withTrashed article relation โ”‚ โ”‚ โ”œโ”€โ”€ Setting.php # get/set/bool with cache invalidation โ”‚ โ”‚ โ”œโ”€โ”€ Tag.php โ”‚ โ”‚ โ”œโ”€โ”€ User.php # isAdmin(), isEditor(), canPublish() โ”‚ โ”‚ โ””โ”€โ”€ ArticleView.php # unique daily view tracking โ”‚ โ””โ”€โ”€ Services/ โ”‚ โ”œโ”€โ”€ AIService.php # OpenAI: summary, tags, SEO, related โ”‚ โ””โ”€โ”€ UploadService.php # saves files to public/uploads/{folder}/ โ”œโ”€โ”€ database/ โ”‚ โ”œโ”€โ”€ migrations/ # 5 migration files โ”‚ โ””โ”€โ”€ seeders/ # 8 seeders โ€” 30 articles, 17 users, 80 tags... โ”œโ”€โ”€ public/ โ”‚ โ”œโ”€โ”€ css/site.css โ”‚ โ”œโ”€โ”€ js/site.js โ”‚ โ”œโ”€โ”€ images/no-image.svg # placeholder for articles without images โ”‚ โ””โ”€โ”€ uploads/ # article images + branding (auto-created) โ”œโ”€โ”€ resources/views/ โ”‚ โ”œโ”€โ”€ admin/ # dashboard, articles, categories, comments, users, settings โ”‚ โ””โ”€โ”€ frontend/ # home, article, category, search, auth, layout โ”œโ”€โ”€ routes/ โ”‚ โ”œโ”€โ”€ web.php # all routes (frontend + admin) โ”‚ โ””โ”€โ”€ console.php # 6 custom Artisan commands โ”œโ”€โ”€ setup.bat # Windows one-click setup โ””โ”€โ”€ setup.sh # Linux/Mac one-click setup

Environment (.env)

Copy .env.example to .env and configure the following key values:

# Application
APP_NAME="News Portal"
APP_URL=http://localhost:8000

# Database
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=news_portal
DB_USERNAME=root
DB_PASSWORD=your_password

# AI โ€” also configurable from Admin โ†’ Settings โ†’ AI
OPENAI_API_KEY=sk-...
OPENAI_MODEL=gpt-4o-mini

# Mail โ€” also configurable from Admin โ†’ Settings โ†’ Email
MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_ENCRYPTION=tls
MAIL_USERNAME=you@gmail.com
MAIL_PASSWORD=your_app_password

Both AI and Email settings can be managed entirely from the Admin panel without editing .env. The .env values serve only as fallbacks.

Roles & Permissions

NewsPortal Pro uses four distinct user roles, each with precisely scoped permissions.

PermissionAdminEditorAuthorReader
Access admin panelโœ“โœ“โœ“โ€”
Create articlesโœ“โœ“โœ“โ€”
Edit own articlesโœ“โœ“โœ“โ€”
Edit all articlesโœ“โœ“โ€”โ€”
Publish articlesโœ“โœ“โ€”โ€”
Delete articlesโœ“โœ“โ€”โ€”
Manage commentsโœ“โœ“โ€”โ€”
Manage categoriesโœ“โœ“โ€”โ€”
Run AI enrichmentโœ“โœ“โœ“โ€”
Manage usersโœ“โ€”โ€”โ€”
Access all settingsโœ“โ€”โ€”โ€”

The Users and Settings menu items are hidden from Editors in the sidebar, and the routes are protected by the is_admin_only middleware. Direct URL access returns a 403.

AI Suite โ€” Overview

NewsPortal Pro integrates with OpenAI's Chat Completions API to provide four intelligent publishing features. All AI functionality is handled by App\Services\AIService.

The site works completely without AI. If no API key is set or AI is disabled, all AI features no-op gracefully with no errors.

AI Feature Toggles

FeatureSetting KeyWhat it does
Summaryai_feature_summaryGenerates a 2โ€“3 sentence neutral summary shown on article cards and detail pages
Tagsai_feature_tagsSuggests and auto-attaches 3โ€“6 relevant tags when an article is published
SEOai_feature_seoGenerates meta title (โ‰ค60 chars) and meta description (โ‰ค155 chars)
Relatedai_feature_relatedSurfaces contextually relevant articles in the sidebar

Configuration

Configure AI from Admin โ†’ Settings โ†’ AI:

  1. Paste your OpenAI API key (from platform.openai.com)
  2. Select your preferred model (gpt-4o-mini is cheapest and recommended)
  3. Toggle the master switch Enable AI Features ON
  4. Toggle individual features as needed
# Manually process AI on all unprocessed articles
$ php artisan news:process-ai

# Process with a limit
$ php artisan news:process-ai --limit=20

# Re-process a specific article by ID
$ php artisan news:reprocess-ai 5

Artisan Commands

Six custom Artisan commands are included in routes/console.php:

CommandDescriptionType
news:statsDisplay full site statistics in a tableUtility
news:process-ai [--limit=N]Run AI enrichment on all unprocessed articlesAI
news:reprocess-ai {id}Force re-run AI on a specific article by IDAI
news:send-newsletter "Subject" [--preview]Email all confirmed subscribersEmail
news:publish-scheduledPublish articles whose scheduled time has passedScheduler
news:clear-spamPermanently delete all spam-flagged commentsUtility

Troubleshooting

Syntax error in Blade views

If you see "unexpected token '='" in a Blade view, ensure you are not using inline associative arrays with => inside @foreach directives. Always move them to a @php block first:

// โŒ Causes XAMPP Blade parser issues
@foreach(['key'=>'value'] as $k => $v)

// โœ… Correct approach
@php $arr = ['key' => 'value']; @endphp
@foreach($arr as $k => $v)

Pagination looks unstyled

Ensure AppServiceProvider::boot() contains:

Paginator::useBootstrapFive();

SQLSTATE: Access denied

Double-check DB_USERNAME and DB_PASSWORD in your .env file. For XAMPP, the default is root with no password.

Uploaded images not appearing

Ensure the public/uploads/ directory exists and is writable. On Linux/Mac, run chmod -R 775 public/uploads.

AI features not working

Check: (1) Admin โ†’ Settings โ†’ AI master switch is ON. (2) API key is set. (3) Your server can reach api.openai.com โ€” some hosts block outbound HTTPS to external APIs.

All errors are logged to storage/logs/laravel.log. Check this file first when debugging unexpected behaviour.

Changelog

v1.0.0 Latest July 2025
  • Initial release with Laravel 12 + PHP 8.2
  • Full AI suite (summary, tags, SEO, related) with per-feature toggles
  • 4-role RBAC system with middleware protection
  • Quill rich text editor integration
  • Scrollable category nav with arrow buttons
  • Bootstrap 5 pagination configured globally
  • 30 seeded articles, 17 users, 80 tags, 150+ comments
  • One-command setup scripts for Windows and Linux/Mac
  • 6 custom Artisan commands
  • SMTP configuration from Admin panel at runtime