<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Language;

use App\Agenda;
use App\Event;
use App\Presse;
use App\Geosite;
use App\Attrib;
use App\Musee;
use App\Presentation;
use App\Monographie;
use App\Guide;
use App\Chiffre;
use App\Charte;
use App\Galerie;
use App\Video;
use App\Depliant;
use App\CategoriePost;
use App\Tag;
use App\Post;
use App\Banner;
use App\Partner;

use App\AgendaTranslations;
use App\EventTranslations;
use App\PresseTranslations;
use App\GeositeTranslations;
use App\AttribTranslations;
use App\PresentationTranslations;
use App\MonographieTranslations;
use App\GuideTranslations;
use App\ChiffreTranslations;
use App\CharteTranslations;
use App\MuseeTranslations;
use App\GaleriesTranslations;
use App\VideoTranslations;
use App\DepliantTranslations;
use App\CategoriePostTranslations;
use App\TagTranslations;
use App\PostTranslations;
use App\BannersTranslations;
use App\PartnerTranslations;

class TranslateController extends Controller
{
    



/*-------------------------------------Actualites--------------------------------------------------------------*/
/*Agenda*/

    public function Agenda()
    {
          $agendas = Agenda::latest()->get();
          $languages = Language::latest()->get();

    return view('admin.Traduction.translate.agendas', compact('agendas','languages'));
  
    }

    public function StoreAgenda(Request $request)
    {
          $agendas = Agenda::latest()->get();
          $languages = Language::latest()->get();
          
          foreach ($agendas as $key => $ga) {
          foreach ($languages as $key => $lang) {
                     
                     //les champe de agendas translater
                    $title = $request['title'.$ga->id.''.$lang->code];
                    $description = $request['description'.$ga->id.''.$lang->code];    
          //dd($title);
              if ($title!=null) {
                     //test si deja agendas transalte with this lang

                      $old_transalte=AgendaTranslations::where('agenda_id',$ga->id)->where('locale',$lang->code)->get();
                        //si deja existe translate donc il faut update 
                         if(count($old_transalte)){

                              $old_translate_ga=AgendaTranslations::find($old_transalte[0]->id);
                              $old_translate_ga->title = $title;
                              $old_translate_ga->description = $description;
                              $old_translate_ga->save();
                             } 
                             //si non il faut create new translate with this lang
                          else{   
                              $new_translate_ga = new AgendaTranslations();
                              $new_translate_ga->agenda_id=$ga->id;
                              $new_translate_ga->locale =$lang->code;
                              $new_translate_ga->title = $title;
                              $new_translate_ga->description = $description;
                              $new_translate_ga->save();
                              }
                         }


          }//end for
          }//end for
       session()->flash('success','Traduction agendas successful');
         return view('admin.Traduction.translate.agendas', compact('agendas','languages'));
  
    }


/*Event*/

    public function Event()
    {
          $events = Event::latest()->get();
          $languages = Language::latest()->get();

    return view('admin.Traduction.translate.events', compact('events','languages'));
  
    }

    public function StoreEvent(Request $request)
    {
          $events = Event::latest()->get();
          $languages = Language::latest()->get();
          
          foreach ($events as $key => $ga) {
          foreach ($languages as $key => $lang) {
                     
                     //les champe de depliants translater
                    $title = $request['title'.$ga->id.''.$lang->code];
                    $description = $request['description'.$ga->id.''.$lang->code];    
          //dd($title);
              if ($title!=null) {
                     //test si deja depliants transalte with this lang

                      $old_transalte=EventTranslations::where('event_id',$ga->id)->where('locale',$lang->code)->get();
                        //si deja existe translate donc il faut update 
                         if(count($old_transalte)){

                              $old_translate_ga=EventTranslations::find($old_transalte[0]->id);
                              $old_translate_ga->title = $title;
                              $old_translate_ga->description = $description;
                              $old_translate_ga->save();
                             } 
                             //si non il faut create new translate with this lang
                          else{   
                              $new_translate_ga = new EventTranslations();
                              $new_translate_ga->event_id=$ga->id;
                              $new_translate_ga->locale =$lang->code;
                              $new_translate_ga->title = $title;
                              $new_translate_ga->description = $description;
                              $new_translate_ga->save();
                              }
                         }


          }//end for
          }//end for
       session()->flash('success','Traduction events successful');
         return view('admin.Traduction.translate.events', compact('events','languages'));
  
    }


/*Presse*/

    public function Presse()
    {
          $presses = Presse::latest()->get();
          $languages = Language::latest()->get();

    return view('admin.Traduction.translate.presses', compact('presses','languages'));
  
    }

    public function StorePresse(Request $request)
    {
          $presses = Presse::latest()->get();
          $languages = Language::latest()->get();
          
          foreach ($presses as $key => $ga) {
          foreach ($languages as $key => $lang) {
                     
                     //les champe de presses translater
                    $title = $request['title'.$ga->id.''.$lang->code];
                    $description = $request['description'.$ga->id.''.$lang->code];    
          //dd($title);
              if ($title!=null) {
                     //test si deja presses transalte with this lang

                      $old_transalte=PresseTranslations::where('presse_id',$ga->id)->where('locale',$lang->code)->get();
                        //si deja existe translate donc il faut update 
                         if(count($old_transalte)){

                              $old_translate_ga=PresseTranslations::find($old_transalte[0]->id);
                              $old_translate_ga->title = $title;
                              $old_translate_ga->description = $description;
                              $old_translate_ga->save();
                             } 
                             //si non il faut create new translate with this lang
                          else{   
                              $new_translate_ga = new PresseTranslations();
                              $new_translate_ga->presse_id=$ga->id;
                              $new_translate_ga->locale =$lang->code;
                              $new_translate_ga->title = $title;
                              $new_translate_ga->description = $description;
                              $new_translate_ga->save();
                              }
                         }


          }//end for
          }//end for
       session()->flash('success','Traduction presses successful');
         return view('admin.Traduction.translate.presses', compact('presses','languages'));
  
    }










/*-------------------------------------Geosites--------------------------------------------------------------*/
/*Geosite*/

    public function Geosite()
    {
          $geosites = Geosite::latest()->get();
          $languages = Language::latest()->get();

    return view('admin.Traduction.translate.geosites', compact('geosites','languages'));
  
    }

    public function StoreGeosite(Request $request)
    {
          $geosites = Geosite::latest()->get();
          $languages = Language::latest()->get();
          
          foreach ($geosites as $key => $ba) {
          foreach ($languages as $key => $lang) {
             //les champe de geosites translater
             $title = $request['title'.$ba->id.''.$lang->code];
              if ($title!=null) {
                     //test si deja geosites transalte with this lang

                   $old_transalte=GeositeTranslations::where('geosite_id',$ba->id)->where('locale',$lang->code)->get();
                        //si deja existe translate donc il faut update 
                         if(count($old_transalte)){
                              $old_translate_ba=GeositeTranslations::find($old_transalte[0]->id);
                              $old_translate_ba->title = $title;
                              $old_translate_ba->save();
                             } 
                             //si non il faut create new translate with this lang
                          else{   
                              $new_translate_ba = new GeositeTranslations();
                              $new_translate_ba->geosite_id=$ba->id;
                              $new_translate_ba->locale =$lang->code;
                              $new_translate_ba->title = $title;
                              $new_translate_ba->save();
                              }
                         }
          }//end for
          }//end for
       
         session()->flash('success','Traduction geosites successful');
         return view('admin.Traduction.translate.geosites', compact('geosites','languages'));
  
    }



/*Attrib*/

    public function Attrib($geosite_id)
    {
          $attribs = Attrib::where('geosite_id',$geosite_id)->get();
          $geosite = Geosite::findOrFail($geosite_id);
          $languages = Language::latest()->get();

    return view('admin.Traduction.translate.attribs', compact('attribs','languages','geosite'));
  
    }

    public function StoreAttrib(Request $request,$geosite_id)
    {
          $attribs = Attrib::where('geosite_id',$geosite_id)->get();
          $geosite = Geosite::findOrFail($geosite_id);
          $languages = Language::latest()->get();
          
          foreach ($attribs as $key => $ga) {
          foreach ($languages as $key => $lang) {
                     
                     //les champe de attribs translater
                    $title = $request['title'.$ga->id.''.$lang->code];
                    $description = $request['description'.$ga->id.''.$lang->code];    
          //dd($title);
              if ($title!=null) {
                     //test si deja attribs transalte with this lang

                      $old_transalte=AttribTranslations::where('attrib_id',$ga->id)->where('locale',$lang->code)->get();
                        //si deja existe translate donc il faut update 
                         if(count($old_transalte)){

                              $old_translate_ga=AttribTranslations::find($old_transalte[0]->id);
                              $old_translate_ga->title = $title;
                              $old_translate_ga->description = $description;
                              $old_translate_ga->save();
                             } 
                             //si non il faut create new translate with this lang
                          else{   
                              $new_translate_ga = new AttribTranslations();
                              $new_translate_ga->attrib_id=$ga->id;
                              $new_translate_ga->locale =$lang->code;
                              $new_translate_ga->title = $title;
                              $new_translate_ga->description = $description;
                              $new_translate_ga->save();
                              }
                         }


          }//end for
          }//end for
       session()->flash('success','Traduction attribs successful');
         return view('admin.Traduction.translate.attribs', compact('attribs','languages','geosite'));
  
    }



/*Musee*/

    public function Musee()
    {
          $musees = Musee::latest()->get();
          $languages = Language::latest()->get();

    return view('admin.Traduction.translate.musees', compact('musees','languages'));
  
    }

    public function StoreMusee(Request $request)
    {
          $musees = Musee::latest()->get();
          $languages = Language::latest()->get();
          
          foreach ($musees as $key => $ga) {
          foreach ($languages as $key => $lang) {
                     
                     //les champe de musees translater
                    $title = $request['title'.$ga->id.''.$lang->code];
                    $description = $request['description'.$ga->id.''.$lang->code];    
          //dd($title);
              if ($title!=null) {
                     //test si deja musees transalte with this lang

                      $old_transalte=MuseeTranslations::where('musee_id',$ga->id)->where('locale',$lang->code)->get();
                        //si deja existe translate donc il faut update 
                         if(count($old_transalte)){

                              $old_translate_ga=MuseeTranslations::find($old_transalte[0]->id);
                              $old_translate_ga->title = $title;
                              $old_translate_ga->description = $description;
                              $old_translate_ga->save();
                             } 
                             //si non il faut create new translate with this lang
                          else{   
                              $new_translate_ga = new MuseeTranslations();
                              $new_translate_ga->musee_id=$ga->id;
                              $new_translate_ga->locale =$lang->code;
                              $new_translate_ga->title = $title;
                              $new_translate_ga->description = $description;
                              $new_translate_ga->save();
                              }
                         }


          }//end for
          }//end for
       session()->flash('success','Traduction musees successful');
         return view('admin.Traduction.translate.musees', compact('musees','languages'));
  
    }





/*-------------------------------------Presentation--------------------------------------------------------------*/
/*Presentation*/

    public function Presentation()
    {
          $present = Presentation::first();
          $languages = Language::latest()->get();

    return view('admin.Traduction.translate.presentations', compact('present','languages'));
  
    }

    public function StorePresentation(Request $request)
    {
          $present = Presentation::first();
          $languages = Language::latest()->get();
          
         if($present){ 
          foreach ($languages as $key => $lang) {
                     
              //les champe de presentations translater
              $title = $request['title'.$present->id.''.$lang->code];
              $subtitle = $request['subtitle'.$present->id.''.$lang->code];
              $description = $request['description'.$present->id.''.$lang->code];
              $title1 = $request['title1'.$present->id.''.$lang->code];
              $subtitle1 = $request['subtitle1'.$present->id.''.$lang->code];
              $description1 = $request['description1'.$present->id.''.$lang->code];
              $description2 = $request['description2'.$present->id.''.$lang->code];
              $description3    = $request['description3'.$present->id.''.$lang->code];
          //dd($title);
              if ($title!=null && $title1!=null) {
                     //test si deja presentations transalte with this lang

                      $old_transalte=PresentationTranslations::where('presentation_id',$present->id)->where('locale',$lang->code)->get();
                        //si deja existe translate donc il faut update 
                         if(count($old_transalte)){

                              $old_translate_ga=PresentationTranslations::find($old_transalte[0]->id);
                              $old_translate_ga->title       = $title;
                              $old_translate_ga->subtitle    = $subtitle;
                              $old_translate_ga->description = $description;
                              $old_translate_ga->title1      = $title1;
                              $old_translate_ga->subtitle1   = $subtitle1;
                              $old_translate_ga->description1 = $description1;
                              $old_translate_ga->description2 = $description2;
                              $old_translate_ga->description3 = $description3;
                              $old_translate_ga->save();
                             } 
                             //si non il faut create new translate with this lang
                          else{   
                              $new_translate_ga = new PresentationTranslations();
                              $new_translate_ga->presentation_id=$present->id;
                              $new_translate_ga->locale =$lang->code;
                              $new_translate_ga->title       = $title;
                              $new_translate_ga->subtitle    = $subtitle;
                              $new_translate_ga->description = $description;
                              $new_translate_ga->title1      = $title1;
                              $new_translate_ga->subtitle1   = $subtitle1;
                              $new_translate_ga->description1 = $description1;
                              $new_translate_ga->description2 = $description2;
                              $new_translate_ga->description3 = $description3;
                              $new_translate_ga->save();
                              }
                         }


          }//end for
           }//end if
       session()->flash('success','Traduction presentations successful');
         return view('admin.Traduction.translate.presentations', compact('present','languages'));
  
    }



/*Monographie*/

    public function Monographie()
    {
          $monographies = Monographie::latest()->get();
          $languages = Language::latest()->get();

    return view('admin.Traduction.translate.monographies', compact('monographies','languages'));
  
    }

    public function StoreMonographie(Request $request)
    {
          $monographies = Monographie::latest()->get();
          $languages = Language::latest()->get();
          
          foreach ($monographies as $key => $ga) {
          foreach ($languages as $key => $lang) {
                     
                     //les champe de monographies translater
                    $title = $request['title'.$ga->id.''.$lang->code];
                    $description = $request['description'.$ga->id.''.$lang->code];    
          //dd($title);
              if ($title!=null) {
                     //test si deja monographies transalte with this lang

                      $old_transalte=MonographieTranslations::where('monographie_id',$ga->id)->where('locale',$lang->code)->get();
                      
                        //si deja existe translate donc il faut update 
                         if(count($old_transalte)){

                              $old_translate_ga=MonographieTranslations::find($old_transalte[0]->id);
                              $old_translate_ga->title = $title;
                              $old_translate_ga->description = $description;
                              $old_translate_ga->save();
                             } 
                             //si non il faut create new translate with this lang
                          else{   
                              $new_translate_ga = new MonographieTranslations();
                              $new_translate_ga->monographie_id=$ga->id;
                              $new_translate_ga->locale =$lang->code;
                              $new_translate_ga->title = $title;
                              $new_translate_ga->description = $description;
                              $new_translate_ga->save();
                              }
                         }


          }//end for
          }//end for
       session()->flash('success','Traduction monographies successful');
         return view('admin.Traduction.translate.monographies', compact('monographies','languages'));
  
    }




/*Guide*/

    public function Guide()
    {
          $guides = Guide::latest()->get();
          $languages = Language::latest()->get();

    return view('admin.Traduction.translate.guides', compact('guides','languages'));
  
    }

    public function StoreGuide(Request $request)
    {
          $guides = Guide::latest()->get();
          $languages = Language::latest()->get();
          
          foreach ($guides as $key => $ga) {
          foreach ($languages as $key => $lang) {
                     
                     //les champe de guides translater
                    $title = $request['title'.$ga->id.''.$lang->code];
                    $description = $request['description'.$ga->id.''.$lang->code];    
          //dd($title);
              if ($title!=null) {
                     //test si deja guides transalte with this lang

                      $old_transalte=GuideTranslations::where('guide_id',$ga->id)->where('locale',$lang->code)->get();
                      
                        //si deja existe translate donc il faut update 
                         if(count($old_transalte)){

                              $old_translate_ga=GuideTranslations::find($old_transalte[0]->id);
                              $old_translate_ga->title = $title;
                              $old_translate_ga->description = $description;
                              $old_translate_ga->save();
                             } 
                             //si non il faut create new translate with this lang
                          else{   
                              $new_translate_ga = new GuideTranslations();
                              $new_translate_ga->guide_id=$ga->id;
                              $new_translate_ga->locale =$lang->code;
                              $new_translate_ga->title = $title;
                              $new_translate_ga->description = $description;
                              $new_translate_ga->save();
                              }
                         }


          }//end for
          }//end for
       session()->flash('success','Traduction guides successful');
         return view('admin.Traduction.translate.guides', compact('guides','languages'));
  
    }


/*Chiffre*/

    public function Chiffre()
    {
          $chiffres = Chiffre::latest()->get();
          $languages = Language::latest()->get();

    return view('admin.Traduction.translate.chiffres', compact('chiffres','languages'));
  
    }

    public function StoreChiffre(Request $request)
    {
          $chiffres = Chiffre::latest()->get();
          $languages = Language::latest()->get();
          
          foreach ($chiffres as $key => $ga) {
          foreach ($languages as $key => $lang) {
                     
                     //les champe de chiffres translater
                    $title = $request['title'.$ga->id.''.$lang->code];
                    $description = $request['description'.$ga->id.''.$lang->code];    
          //dd($title);
              if ($title!=null) {
                     //test si deja chiffres transalte with this lang

                      $old_transalte=ChiffreTranslations::where('chiffre_id',$ga->id)->where('locale',$lang->code)->get();
                      
                        //si deja existe translate donc il faut update 
                         if(count($old_transalte)){

                              $old_translate_ga=ChiffreTranslations::find($old_transalte[0]->id);
                              $old_translate_ga->title = $title;
                              $old_translate_ga->description = $description;
                              $old_translate_ga->save();
                             } 
                             //si non il faut create new translate with this lang
                          else{   
                              $new_translate_ga = new ChiffreTranslations();
                              $new_translate_ga->chiffre_id=$ga->id;
                              $new_translate_ga->locale =$lang->code;
                              $new_translate_ga->title = $title;
                              $new_translate_ga->description = $description;
                              $new_translate_ga->save();
                              }
                         }


          }//end for
          }//end for
       session()->flash('success','Traduction chiffres successful');
         return view('admin.Traduction.translate.chiffres', compact('chiffres','languages'));
  
    }


/*Charte*/

    public function Charte()
    {
          $chartes = Charte::latest()->get();
          $languages = Language::latest()->get();

    return view('admin.Traduction.translate.chartes', compact('chartes','languages'));
  
    }

    public function StoreCharte(Request $request)
    {
          $chartes = Charte::latest()->get();
          $languages = Language::latest()->get();
          
          foreach ($chartes as $key => $ba) {
          foreach ($languages as $key => $lang) {
                     
                     //les champe de chartes translater
                    $title = $request['title'.$ba->id.''.$lang->code];
          //dd($title);
              if ($title!=null) {
                     //test si deja chartes transalte with this lang

                      $old_transalte=CharteTranslations::where('charte_id',$ba->id)->where('locale',$lang->code)->get();
                        //si deja existe translate donc il faut update 
                         if(count($old_transalte)){

                              $old_translate_ba=CharteTranslations::find($old_transalte[0]->id);
                              $old_translate_ba->title = $title;
                              $old_translate_ba->save();
                             } 
                             //si non il faut create new translate with this lang
                          else{   
                              $new_translate_ba = new CharteTranslations();
                              $new_translate_ba->charte_id=$ba->id;
                              $new_translate_ba->locale =$lang->code;
                              $new_translate_ba->title = $title;
                              $new_translate_ba->save();
                              }
                         }


          }//end for
          }//end for
       session()->flash('success','Traduction chartes successful');
         return view('admin.Traduction.translate.chartes', compact('chartes','languages'));
  
    }





















/*-------------------------------------WEB Setting--------------------------------------------------------------*/

/*Banner*/

    public function Banner()
    {
          $banners = Banner::latest()->get();
          $languages = Language::latest()->get();

    return view('admin.Traduction.translate.banners', compact('banners','languages'));
  
    }

    public function StoreBanner(Request $request)
    {
          $banners = Banner::latest()->get();
          $languages = Language::latest()->get();
          
          foreach ($banners as $key => $ba) {
          foreach ($languages as $key => $lang) {
                     
                     //les champe de banners translater
                    $title = $request['title'.$ba->id.''.$lang->code];
                    $subtitle = $request['subtitle'.$ba->id.''.$lang->code];    
          //dd($title);
              if ($title!=null) {
                     //test si deja banners transalte with this lang

                      $old_transalte=BannersTranslations::where('banner_id',$ba->id)->where('locale',$lang->code)->get();
                        //si deja existe translate donc il faut update 
                         if(count($old_transalte)){

                              $old_translate_ba=BannersTranslations::find($old_transalte[0]->id);
                              $old_translate_ba->title = $title;
                              $old_translate_ba->subtitle = $subtitle;
                              $old_translate_ba->save();
                             } 
                             //si non il faut create new translate with this lang
                          else{   
                              $new_translate_ba = new BannersTranslations();
                              $new_translate_ba->banner_id=$ba->id;
                              $new_translate_ba->locale =$lang->code;
                              $new_translate_ba->title = $title;
                              $new_translate_ba->subtitle = $subtitle;
                              $new_translate_ba->save();
                              }
                         }


          }//end for
          }//end for
       session()->flash('success','Traduction Sliders successful');
         return view('admin.Traduction.translate.banners', compact('banners','languages'));
  
    }



/*Partner*/

    public function Partner()
    {
          $partners = Partner::latest()->get();
          $languages = Language::latest()->get();

    return view('admin.Traduction.translate.partners', compact('partners','languages'));
  
    }

    public function StorePartner(Request $request)
    {
          $partners = Partner::latest()->get();
          $languages = Language::latest()->get();
          
          foreach ($partners as $key => $ba) {
          foreach ($languages as $key => $lang) {
                     
                     //les champe de partners translater
                    $title = $request['title'.$ba->id.''.$lang->code];
          //dd($title);
              if ($title!=null) {
                     //test si deja partners transalte with this lang

                      $old_transalte=PartnerTranslations::where('partner_id',$ba->id)->where('locale',$lang->code)->get();
                        //si deja existe translate donc il faut update 
                         if(count($old_transalte)){

                              $old_translate_ba=PartnerTranslations::find($old_transalte[0]->id);
                              $old_translate_ba->title = $title;
                              $old_translate_ba->save();
                             } 
                             //si non il faut create new translate with this lang
                          else{   
                              $new_translate_ba = new PartnerTranslations();
                              $new_translate_ba->partner_id=$ba->id;
                              $new_translate_ba->locale =$lang->code;
                              $new_translate_ba->title = $title;
                              $new_translate_ba->save();
                              }
                         }


          }//end for
          }//end for
       session()->flash('success','Traduction partners successful');
         return view('admin.Traduction.translate.partners', compact('partners','languages'));
  
    }











/*Galerie*/

    public function Galerie()
    {
          $galeries = Galerie::latest()->get();
          $languages = Language::latest()->get();

    return view('admin.Traduction.translate.galeries', compact('galeries','languages'));
  
    }

    public function StoreGalerie(Request $request)
    {
          $galeries = Galerie::latest()->get();
          $languages = Language::latest()->get();
          
          foreach ($galeries as $key => $ga) {
          foreach ($languages as $key => $lang) {
                     
                     //les champe de galeries translater
                    $titre = $request['titre'.$ga->id.''.$lang->code];
                    $description = $request['description'.$ga->id.''.$lang->code];    
          //dd($titre);
              if ($titre!=null) {
                     //test si deja galeries transalte with this lang

                      $old_transalte=GaleriesTranslations::where('galerie_id',$ga->id)->where('locale',$lang->code)->get();
                        //si deja existe translate donc il faut update 
                         if(count($old_transalte)){

                              $old_translate_ga=GaleriesTranslations::find($old_transalte[0]->id);
                              $old_translate_ga->titre = $titre;
                              $old_translate_ga->description = $description;
                              $old_translate_ga->save();
                             } 
                             //si non il faut create new translate with this lang
                          else{   
                              $new_translate_ga = new GaleriesTranslations();
                              $new_translate_ga->galerie_id=$ga->id;
                              $new_translate_ga->locale =$lang->code;
                              $new_translate_ga->titre = $titre;
                              $new_translate_ga->description = $description;
                              $new_translate_ga->save();
                              }
                         }


          }//end for
          }//end for
       session()->flash('success','Traduction galeries successful');
         return view('admin.Traduction.translate.galeries', compact('galeries','languages'));
  
    }


/*video*/

    public function Video()
    {
          $videos = Video::latest()->get();
          $languages = Language::latest()->get();

    return view('admin.Traduction.translate.videos', compact('videos','languages'));
  
    }

    public function StoreVideo(Request $request)
    {
          $videos = Video::latest()->get();
          $languages = Language::latest()->get();
          
          foreach ($videos as $key => $ga) {
          foreach ($languages as $key => $lang) {
                     
                     //les champe de videos translater
                    $title = $request['title'.$ga->id.''.$lang->code];
                    $description = $request['description'.$ga->id.''.$lang->code];    
          //dd($title);
              if ($title!=null) {
                     //test si deja videos transalte with this lang

                      $old_transalte=VideoTranslations::where('video_id',$ga->id)->where('locale',$lang->code)->get();
                        //si deja existe translate donc il faut update 
                         if(count($old_transalte)){

                              $old_translate_ga=VideoTranslations::find($old_transalte[0]->id);
                              $old_translate_ga->title = $title;
                              $old_translate_ga->description = $description;
                              $old_translate_ga->save();
                             } 
                             //si non il faut create new translate with this lang
                          else{   
                              $new_translate_ga = new VideoTranslations();
                              $new_translate_ga->video_id=$ga->id;
                              $new_translate_ga->locale =$lang->code;
                              $new_translate_ga->title = $title;
                              $new_translate_ga->description = $description;
                              $new_translate_ga->save();
                              }
                         }


          }//end for
          }//end for
       session()->flash('success','Traduction Videos successful');
         return view('admin.Traduction.translate.videos', compact('videos','languages'));
  
    }


/*Depliant*/

    public function Depliant()
    {
          $depliants = Depliant::latest()->get();
          $languages = Language::latest()->get();

    return view('admin.Traduction.translate.depliants', compact('depliants','languages'));
  
    }

    public function StoreDepliant(Request $request)
    {
          $depliants = Depliant::latest()->get();
          $languages = Language::latest()->get();
          
          foreach ($depliants as $key => $ga) {
          foreach ($languages as $key => $lang) {
                     
                     //les champe de depliants translater
                    $title = $request['title'.$ga->id.''.$lang->code];
                    $description = $request['description'.$ga->id.''.$lang->code];    
          //dd($title);
              if ($title!=null) {
                     //test si deja depliants transalte with this lang

                      $old_transalte=DepliantTranslations::where('depliant_id',$ga->id)->where('locale',$lang->code)->get();
                        //si deja existe translate donc il faut update 
                         if(count($old_transalte)){

                              $old_translate_ga=DepliantTranslations::find($old_transalte[0]->id);
                              $old_translate_ga->title = $title;
                              $old_translate_ga->description = $description;
                              $old_translate_ga->save();
                             } 
                             //si non il faut create new translate with this lang
                          else{   
                              $new_translate_ga = new DepliantTranslations();
                              $new_translate_ga->depliant_id=$ga->id;
                              $new_translate_ga->locale =$lang->code;
                              $new_translate_ga->title = $title;
                              $new_translate_ga->description = $description;
                              $new_translate_ga->save();
                              }
                         }


          }//end for
          }//end for
       session()->flash('success','Traduction depliants successful');
         return view('admin.Traduction.translate.depliants', compact('depliants','languages'));
  
    }










            /*---------------------Blog-------------------------------*/


    public function CategoriePost()
    {
          $categorieposts = CategoriePost::latest()->get();
          $languages = Language::latest()->get();

    return view('admin.Traduction.translate.categorieposts', compact('categorieposts','languages'));
  
    }

    public function StoreCategoriePost(Request $request)
    {
          $categorieposts = CategoriePost::latest()->get();
          $languages = Language::latest()->get();
          
          foreach ($categorieposts as $key => $ca) {
          foreach ($languages as $key => $lang) {
                     
                     //les champe de categorieposts translater
                    $name = $request['name'.$ca->id.''.$lang->code];
          //dd($name);
              if ($name!=null) {
                     //test si deja categorieposts transalte with this lang

                      $old_transalte=CategoriePostTranslations::where('categorie_post_id',$ca->id)->where('locale',$lang->code)->get();
                        //si deja existe translate donc il faut update 
                         if(count($old_transalte)){

                              $old_translate_ca=CategoriePostTranslations::find($old_transalte[0]->id);
                              $old_translate_ca->name = $name;
                              $old_translate_ca->save();
                             } 
                             //si non il faut create new translate with this lang
                          else{   
                              $new_translate_ca = new CategoriePostTranslations();
                              $new_translate_ca->categorie_post_id=$ca->id;
                              $new_translate_ca->locale =$lang->code;
                              $new_translate_ca->name = $name;
                              $new_translate_ca->save();
                              }
                         }


          }//end for
          }//end for
       session()->flash('success','Traduction categorie posts successful');
         return view('admin.Traduction.translate.categorieposts', compact('categorieposts','languages'));
  
    }





    public function Tag()
    {
          $tags = Tag::latest()->get();
          $languages = Language::latest()->get();

    return view('admin.Traduction.translate.tags', compact('tags','languages'));
  
    }

    public function StoreTag(Request $request)
    {
          $tags = Tag::latest()->get();
          $languages = Language::latest()->get();
          
          foreach ($tags as $key => $tag) {
          foreach ($languages as $key => $lang) {
                     
                     //les champe de tags translater
                    $name = $request['name'.$tag->id.''.$lang->code];
          //dd($name);
              if ($name!=null) {
                     //test si deja tags transalte with this lang

                      $old_transalte=TagTranslations::where('tag_id',$tag->id)->where('locale',$lang->code)->get();
                        //si deja existe translate donc il faut update 
                         if(count($old_transalte)){

                              $old_translate_ca=TagTranslations::find($old_transalte[0]->id);
                              $old_translate_ca->name = $name;
                              $old_translate_ca->save();
                             } 
                             //si non il faut create new translate with this lang
                          else{   
                              $new_translate_ca = new TagTranslations();
                              $new_translate_ca->tag_id=$tag->id;
                              $new_translate_ca->locale =$lang->code;
                              $new_translate_ca->name = $name;
                              $new_translate_ca->save();
                              }
                         }


          }//end for
          }//end for
       session()->flash('success','Traduction tags successful');
         return view('admin.Traduction.translate.tags', compact('tags','languages'));
  
    }

            /*post*/

    public function Post()
    {
          $posts = Post::latest()->get();
          $languages = Language::latest()->get();

    return view('admin.Traduction.translate.posts', compact('posts','languages'));
  
    }

    public function StorePost(Request $request)
    {
          $posts = Post::latest()->get();
          $languages = Language::latest()->get();
          
          foreach ($posts as $key => $post) {
          foreach ($languages as $key => $lang) {
                     
                     //les champe de posts translater
                    $title = $request['title'.$post->id.''.$lang->code];
                    $description = $request['description'.$post->id.''.$lang->code];    
          //dd($title);
              if ($title!=null) {
                     //test si deja posts transalte with this lang

                      $old_transalte=PostTranslations::where('post_id',$post->id)->where('locale',$lang->code)->get();
                        //si deja existe translate donc il faut update 
                         if(count($old_transalte)){

                              $old_translate_ga=PostTranslations::find($old_transalte[0]->id);
                              $old_translate_ga->title = $title;
                              $old_translate_ga->description = $description;
                              $old_translate_ga->save();
                             } 
                             //si non il faut create new translate with this lang
                          else{   
                              $new_translate_ga = new PostTranslations();
                              $new_translate_ga->post_id=$post->id;
                              $new_translate_ga->locale =$lang->code;
                              $new_translate_ga->title = $title;
                              $new_translate_ga->description = $description;
                              $new_translate_ga->save();
                              }
                         }


          }//end for
          }//end for
       session()->flash('success','Traduction posts successful');
         return view('admin.Traduction.translate.posts', compact('posts','languages'));
  
    }

/*-------------------------------*/



}
