<?php

namespace App\Http\Controllers;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\App;
use Illuminate\Http\Request;
use App\Models\Admin\User;
use Session;
use URL;
class AppController extends Controller{


	//for admin to set local in users table
	public function setlocaleA($locale='ar'){
	  if(!in_array($locale,['en','ar'])){
	    $locale='ar';
	  }
	  if (!empty(Auth::id())) {
	  	Session::put('language',$locale);
		Session::put('locale',$locale);
	  	App::setLocale($locale);

		$post = User::find(Auth::id());
		$post->locale = $locale;
		$post->save();
	  }else{
	  	Session::flush();
	  	Session::put('language',$locale);
	  	Session::put('locale',$locale);
	  	App::setLocale($locale);
	  }
	  return redirect(url(URL::previous()));
	}

	//change admin theme

	public function ChangeTheme($theme='default'){
	  $post = User::find(Auth::id());
	  $post->theme = $theme;
	  $post->save();
	  return redirect(url(URL::previous()));

	}
}
