<?php

namespace App\Http\Controllers\backend;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\Produit;
use App\Models\User;
use App\Notifications\PromotionNotification;
use \Illuminate\Notifications\Notifiable;

use App\Models\Promotion;

class PromotionController extends Controller
{
   public function __construct(){
      return $this->middleware(['auth','verified']);

  }
  

    public function Index(){

        $articles = Promotion::get();

        return view("backend.promotion.index",compact('articles'));
     }

  

     public function create(){
        $produits = Produit::select('nom', 'id')->oldest('nom')->get();
        

        return view('backend.promotion.add',compact('produits'));
     }
     public function store(Request $request) {

        
      
        $article = new Promotion();
        $article->titre = $request->input('titre');
        $article->produit_id = $request->input('produits');
        $article->debut = $request->input('debut');
        $article->fin = $request->input('fin');


        $article->description = $request->input('description');
        $article->remise = $request->input('remise');
        

        $article->save();
           return redirect('/promotions');

    }
      
     public function createPack(){
        
        return view('backend.promotion.Pack');

        
     }
     public function DeleteAuto(){
        
        
          $stale_posts = Promotion::where('fin', '<',\Carbon\Carbon::now())->get();

          foreach ($stale_posts as $post) {
            $post->delete();
        }
     
     }
}
