Untitled

mail@pastecode.io avatar
unknown
plain_text
4 months ago
2.3 kB
8
Indexable
<?php

namespace App\Http\Controllers\Backend;

use App\Http\Controllers\Controller;
use App\Models\BannerEvent;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;

class BannerEventController extends Controller
{
    public function create()
    {
        return view('/banner/banner-event-skeleton-form');
    }

    public function store(Request $request)
    {
        $request->validate([
            'bannerEventSkeletonName' => 'required|string|max:255',
            'bannerEventSkeletonImage' => 'required|image|mimes:jpeg,png,jpg,gif|max:2048',
            'postBannerEventTemplateImage' => 'required|image|mimes:jpeg,png,jpg,gif|max:2048',
        ]);

        $bannerEventSkeletonImagePath = $request->file('bannerEventSkeletonImage')->store('banner_event_skeleton_image', 'public');
        $postBannerEventTemplateImagePath = $request->file('postBannerEventTemplateImage')->store('post_banner_event_template_image', 'public');

        BannerEvent::create([
            'banner_event_skeleton_name' => $request->bannerEventSkeletonName,
            'banner_event_skeleton_image' => $bannerEventSkeletonImagePath,
            'post_banner_event_template_image' => $postBannerEventTemplateImagePath,
        ]);

        // return redirect()->back()->with('success', 'Banner template saved successfully!');
        return redirect()->route('banner-event-skeleton-listing-page')->with('success', 'Banner template saved successfully!');
    }

    public function showBannerEventSkeletonListingPage()
    {
        $bannerEventSkeletonTemplates = BannerEvent::all();
        return view('/banner/banner-event-skeleton-listing-page', compact('bannerEventSkeletonTemplates'));
    }

    public function destroy($id)
    {
        $banner = BannerEvent::findOrFail($id);
        
        // Delete the banner images from storage
        Storage::disk('public')->delete($banner->banner_event_skeleton_image);
        Storage::disk('public')->delete($banner->post_banner_event_template_image);
        
        // Delete the banner from the database
        $banner->delete();
        
        return redirect()->back()->with('success', 'Banner deleted successfully!');
    }
}
Leave a Comment