PromotionController.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace App\Http\Controllers\backend;
  3. use App\Http\Controllers\Controller;
  4. use Illuminate\Http\Request;
  5. use App\Models\Produit;
  6. use App\Models\User;
  7. use App\Notifications\PromotionNotification;
  8. use \Illuminate\Notifications\Notifiable;
  9. use App\Models\Promotion;
  10. class PromotionController extends Controller
  11. {
  12. public function __construct(){
  13. return $this->middleware(['auth','verified']);
  14. }
  15. public function Index(){
  16. $articles = Promotion::get();
  17. return view("backend.promotion.index",compact('articles'));
  18. }
  19. public function create(){
  20. $produits = Produit::select('nom', 'id')->oldest('nom')->get();
  21. return view('backend.promotion.add',compact('produits'));
  22. }
  23. public function store(Request $request) {
  24. $article = new Promotion();
  25. $article->titre = $request->input('titre');
  26. $article->produit_id = $request->input('produits');
  27. $article->debut = $request->input('debut');
  28. $article->fin = $request->input('fin');
  29. $article->description = $request->input('description');
  30. $article->remise = $request->input('remise');
  31. $article->save();
  32. return redirect('/promotions');
  33. }
  34. public function createPack(){
  35. return view('backend.promotion.Pack');
  36. }
  37. public function DeleteAuto(){
  38. $stale_posts = Promotion::where('fin', '<',\Carbon\Carbon::now())->get();
  39. foreach ($stale_posts as $post) {
  40. $post->delete();
  41. }
  42. }
  43. }