Current File : //home/tradevaly/text.tradevaly.com.bd/app/Http/Controllers/Admin/VideoBannerController.php
<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\Setting;
use Brian2694\Toastr\Facades\Toastr;
use Carbon\Carbon;
use Illuminate\Support\Facades\Storage;
use Intervention\Image\Facades\Image;

class VideoBannerController extends Controller
{
    public function index(){
        return view('backend.pages.setting.home.video_banner.index');
    }

    public function update(Request $request){
        if($request->hasFile('image'))
             {
                $setting_photo = Setting::where('name', 'video_banner_photo')->first()->value;
             $image=$request->file('image');
             $currentDate=Carbon::now()->toDateString();
             $imageName=$currentDate.'-'.uniqid().'.'.$image->getClientOriginalExtension();
             if(Storage::disk('public')->exists('setting/'.$setting_photo))
             {
                Storage::disk('public')->delete('setting/'.$setting_photo);
             }
                    if($image->getClientOriginalExtension() == 'gif'){
                            Storage::disk('public')->put('setting/',$image);
                          $imageName = $image->hashName();
                     }
                     else{

                           $bannerImage = Image::make($image)->resize(1920,308)->stream();
                            Storage::disk('public')->put('setting/'.$imageName,$bannerImage);
                     }
                     Setting::where('name', 'video_banner_photo')->update(['value' => $imageName]);
             }
             Setting::where('name', 'video_banner_link')->update(['value' => $request->video_banner_link]);
             Toastr::success('Success!','Video Banner Updated successfully!');
             return back();

    }
}