MIF_E31211972/app/Console/Commands/CheckLowCoffeeStock.php

36 lines
980 B
PHP

<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Models\Kopi; // pastikan model Kopi sudah ada
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Notification;
use App\Notifications\LowStockNotification; // buat notifikasi sesuai langkah berikutnya
class CheckLowCoffeeStock extends Command
{
protected $signature = 'stock:check-low-coffee';
protected $description = 'Check coffee stocks with low stock and send notifications';
public function __construct()
{
parent::__construct();
}
public function handle()
{
$lowStockCoffees = Kopi::whereColumn('stok', '<=', 'stock_threshold')->get();
foreach ($lowStockCoffees as $coffee) {
// Kirim notifikasi
Notification::route('mail', 'admin@example.com')
->notify(new LowStockNotification($coffee));
}
Log::info('Checked low coffee stocks and sent notifications.');
}
}