FEATURE: make settings translatable

This commit is contained in:
Michal Kváček
2016-07-23 21:47:20 +02:00
parent b89941b909
commit ab3d8eab41
11 changed files with 150 additions and 47 deletions
+41 -6
View File
@@ -3,12 +3,26 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
class Settings extends Model
{
protected $table = 'settings';
public $timestamps = false;
protected $fillable = ['key', 'value'];
protected $fillable = ['key', 'value', 'language'];
/**
* Prepares common query for selecting settings
*
* @return mixed
*/
protected function getSettingsQuery()
{
return Settings::select(['key', 'value', 'language'])
->where('language', LaravelLocalization::getCurrentLocale())
->orWhere('language', null)
->orderBy('language', 'DESC');
}
/**
* Load all settings
@@ -17,12 +31,33 @@ class Settings extends Model
*/
public function getAll()
{
$settings = Settings::select(['key', 'value'])
->get();
$settings = $this->getSettingsQuery()
->get();
return $this->returnPairs($settings);
}
/**
* Get all settings with language info
*
* @return \stdClass
*/
public function getAllWithLanguage()
{
$settings = $this->getSettingsQuery()
->get();
$data = new \stdClass();
foreach ($settings as $conf) {
$data->{$conf->key} = [
'val' => $conf->value,
'lang' => $conf->language
];
}
return $data;
}
/**
* Load only config for views
*
@@ -30,9 +65,9 @@ class Settings extends Model
*/
public function getForView()
{
$settings = Settings::select(['key', 'value'])
->where('load_into_views', 1)
->get();
$settings = $this->getSettingsQuery()
->where('load_into_views', 1)
->get();
return $this->returnPairs($settings);
}