?
Current File : /home/sanghavirealty/www/appazwer/Http/Controllers/LeadershipController.php
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Auth;
use Image;
use Session;

use Carbon\Carbon;
use App\Models\Leadership;
use App\Models\Widget;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\Storage;



class LeadershipController extends Controller
{
    

    public static function leadershipList(){

     if(empty($slug)){
      $slug = date('Y');
     $team =  Leadership::gettheTeam();
     }else{
      // $team = Leadership::gettheTeam($slug);

    

     }
       
     $slugurl = $slug ;
 
      

        return view('leadership.leadership-team',[
         
          'teamList' => $team,
      
               
        ]);



      }

      
    public static function donorList($slug = 0){

      if(empty($slug)){
        $slug = date('Y');
      $team =  Leadership::gettheTeam();
      }else{
       $team = Leadership::gettheTeam($slug);
 
     
 
      }
       
      $slugurl = $slug ;
       
 
         return view('leadership.donor-list',[
          
           'teamList' => $team,
        
           'yearSelected' => $slugurl,
                
         ]);
 
 
 
       }


      public static function dropleadership($lid,$id){

        //course is deleted is deleted , it is not recoverabl
       
        $Product =  Leadership::find($lid) ;
       
        if(is_numeric($lid) == true && is_numeric($id) == 16 && $Product->currentstatus == 0){
       
         $clear =  Leadership::find($lid)->delete() ;
       
         return redirect()->back()->with('msg', 'Record has been deleted');
        
       }else{
       
       
         return abort(403) ;
       
       }

      }




      public static function updateleadership (Request $req) {

        $getUserID = Auth::user()->id ;
        $getproductid = $req->id;

  
    

      
        if( empty($getproductid) )
        {
        
          $req->validate([
            'name' => 'required',
            'designation' => 'required',
            'year' => 'required|not_in:0',
              ]
            );
          
            $title = $req->title ;



            $code =  strtoupper(Str::uuid());
    
            Leadership::insert([

    'section'=>$req->section,
    'name'=>$req->name,
    'designation'=>$req->designation,
    'year'=>$req->year,
    'sociallink1'=>$req->sociallink1,
    'sociallink2'=>$req->sociallink2,
    'phone'=>$req->phone,
    'address'=>$req->address,
    'code'=>$code,

    'createby'=>$getUserID,
    'createdate'=>Carbon::Now(),
    'createip'=>$req->ip()

    ]);
    
    
    $getlastdata =  Leadership::WHERE('currentstatus','0')
           ->WHERE('code',$code)
           ->orderBy('id', 'DESC')
           ->first();
    $getlastID = $getlastdata->id ;
    
        }else {
    
          $getlastID = $getproductid ;
       
          $PostUpdate = Leadership::find($getlastID) ; 

    $PostUpdate->section=$req->section;
    $PostUpdate->name=$req->name;
    $PostUpdate->designation=$req->designation;
    $PostUpdate->year=$req->year;
    $PostUpdate->brief=$req->brief;
    $PostUpdate->sociallink1=$req->sociallink1;
    $PostUpdate->sociallink2=$req->sociallink2;
    $PostUpdate->phone=$req->phone;
    $PostUpdate->address=$req->address;
  
    $PostUpdate->modifyby = $getUserID ;
    $PostUpdate->modifyip = $req->ip() ;
    $PostUpdate->modifydate = Carbon::Now() ;

 
    $PostUpdate->isDirty('section');
    $PostUpdate->isDirty('name');
    
    $PostUpdate->isDirty('designation');
   
    $PostUpdate->isDirty('year');
    $PostUpdate->isDirty('brief');
    $PostUpdate->isDirty('sociallink1');
    $PostUpdate->isDirty('sociallink2');
    $PostUpdate->isDirty('phone');
    $PostUpdate->isDirty('address');

    $PostUpdate->isDirty('modifyby');
    $PostUpdate->isDirty('modifyip');
    $PostUpdate->isDirty('modifydate');

    $PostUpdate->save();
    
        }      
          

    
    
        if($req->hasfile('uploadImage'))
        {
          $indexcount = 1 ;
    
           foreach($req->file('uploadImage') as $file)
           {
    
            
    
            $getExt = $file->extension();
            $random = substr(md5(mt_rand()), 0, 5);
            $fileName = 'leadership'.$getlastID.'_'.$random.'.'.$getExt ;        
            $path = $file->storeAs('public/leadership/', $fileName );
            // $path = $file->storeAs('public/leadership/thumb', $fileName );
            // .$indexcount 
            $ListImageUpdate = Leadership::where('id',$getproductid)->update(['image'=> $fileName]);
            // $ListImageUpdate = Leadership::where('id',$getproductid)->update(['thumbnail' => $fileName]);
    
            $indexcount++ ;
    
            // echo  $fileName ;
          
           }
          
          }
          $gettheSection = Leadership::find($getlastID) ;

          $getSection = $gettheSection->section ;
    
          return redirect('admin-leadership-manager'.'/'.$getSection)->with('success', 'Record has been updated!');
    
    
        }
    
      public static function loadleadershipInForm ($slug = 0){
    
        $section = Widget::ShowData('LeadershipSection');
    
    //  dd($slug);
    
    
        if(!empty($slug)){
    
        $dataviewer = Leadership::find($slug) ; 
        
   
    
        } else {
    
          $dataviewer = 0 ;
    
        }
    
        return view('leadership.leadership-create',[
          'data' => $dataviewer,
          'section'=>$section,
     
        
        ]);
    
    
      }
    
    
      public static function loadleadershipList($slug){

      
    
        if($slug == 121 OR $slug == 123){

      
          $dataviewer = Leadership::Where('currentstatus','0')
          ->Where('section',$slug)
          ->paginate(20);

        }else {

          $dataviewer = Leadership::Where('currentstatus','0')
       
          ->paginate(20);



        }

    
    
    
        return view('leadership.leadership-manager',[
          'dataviewer' => $dataviewer,
        
        
        ]);
    
    
      }


}