Current File : /home/tradevaly/www/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();

    }
    
    public function sortVedio(Request $request,$type)
    {
        $setting_video = Setting::where('name', 'sort_video_file')->first()->value;
        if($type == 'video_url'){
            Setting::where('name', 'sort_video_type')->update(['value' => $type]);
            Setting::where('name', 'sort_video_url')->update(['value' => $request->sort_video_url]);
            
            if(Storage::disk('public')->exists('setting/'.$setting_video))
             {
                Storage::disk('public')->delete('setting/'.$setting_video);
                Setting::where('name', 'sort_video_file')->update(['value' => '']);
          }
        }
        
        if($type == 'video_file'){
           
             if($request->hasFile('sort_video_file'))
             {
                Setting::where('name', 'sort_video_url')->update(['value' => '']);
             $image=$request->file('sort_video_file');
             $currentDate=Carbon::now()->toDateString();
             $imageName=$currentDate.'-'.uniqid().'.'.$image->getClientOriginalExtension();
             if(Storage::disk('public')->exists('setting/'.$setting_video))
             {
                Setting::where('name', 'sort_video_file')->update(['value' => '']);
                Storage::disk('public')->delete('setting/'.$setting_video);
             }
              Storage::disk('public')->put('setting/',$image);
               $imageName = $image->hashName();
              Setting::where('name', 'sort_video_file')->update(['value' => $imageName]);
             }
             Setting::where('name', 'sort_video_type')->update(['value' => $type]);
           
        }
        
        Toastr::success('Success!','Short Video Updated successfully!');
        return back();
    }
}