Day 10 โ€“ Finalizing the Forecast System: Dashboard, Auth & Deployment #SalesForecastAI #LaravelDashboard #ForecastDeployment #ProductionReady #SecureAnalytics


On the final day, weโ€™ll wrap up the AI-powered sales forecasting system by:

  • Securing access with authentication
  • Polishing the dashboard UI
  • Adding final routes and links
  • Preparing for production deployment

๐Ÿ” Step 1: Protect forecast routes with auth middleware

In routes/web.php, group all forecast routes:

Route::middleware('auth')->group(function () {
    Route::get('/sales', [SalesController::class, 'index'])->name('sales.index');
    Route::post('/forecast/insights', [SalesController::class, 'generateInsights'])->name('forecast.insights');
    Route::get('/forecast/image', [SalesController::class, 'forecastImage'])->name('forecast.image');
    Route::get('/forecast/export/csv', fn() => Excel::download(new ForecastExport, 'forecast_report.csv'))->name('forecast.export.csv');
    Route::get('/forecast/export/pdf', function () {
        $data = \App\Models\ForecastResult::orderBy('forecast_date')->get();
        $pdf = \PDF::loadView('forecast.pdf', compact('data'));
        return $pdf->download('forecast_report.pdf');
    })->name('forecast.export.pdf');
});

Enable login system (if not already):

composer require laravel/ui
php artisan ui bootstrap --auth
npm install && npm run dev
php artisan migrate

๐Ÿงผ Step 2: Clean up the dashboard layout

Update sales/index.blade.php with headings, spacing, and layout structure:

<x-app-layout>
    <x-slot name="header">
        <h2 class="text-xl font-semibold">Sales Forecast Dashboard</h2>
    </x-slot>

    <div class="my-6">
        <canvas id="forecastChart" height="120"></canvas>
    </div>

    <div class="mt-6">
        <form method="POST" action="{{ route('forecast.insights') }}">
            @csrf
            <button class="bg-orange-500 text-white px-4 py-2 rounded">Generate AI Insight</button>
        </form>
    </div>

    @if(session('forecast_insight'))
        <div class="bg-orange-100 text-orange-900 p-3 rounded mt-4 whitespace-pre-wrap">
            {!! nl2br(e(session('forecast_insight'))) !!}
        </div>
    @endif

    <div class="flex gap-4 mt-6">
        <a href="{{ route('forecast.export.csv') }}" class="bg-green-500 text-white px-4 py-2 rounded">Export CSV</a>
        <a href="{{ route('forecast.export.pdf') }}" class="bg-red-500 text-white px-4 py-2 rounded">Download PDF</a>
    </div>
</x-app-layout>

๐Ÿš€ Step 3: Prepare for deployment

Set the following in .env.production:

APP_ENV=production
APP_DEBUG=false
LOG_CHANNEL=stack
QUEUE_CONNECTION=database

Then:

php artisan config:cache
php artisan route:cache
php artisan view:cache
php artisan storage:link

Deploy to Laravel Forge, DigitalOcean, or any host with PHP 8+ and Python support.


โœ… Final Features Recap

  • Sales chart with real-time and forecasted data
  • CSV + PDF export
  • GPT-generated insights
  • Anomaly detection
  • Role-based access
  • Artisan-powered Python integration
See also  Day 9 โ€“ Exporting Forecast Reports to CSV and PDF in Laravel #SalesForecastAI #LaravelPDFExport #CSVReport #ForecastReporting #SalesAnalytics

๐ŸŽ‰ Your AI-powered Laravel Sales Forecasting System is now complete and production-ready.
Youโ€™ve built a full-stack tool combining real data, AI prediction, and business-ready reporting โ€” all in 10 days.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.