From: soufiane Date: Mon, 14 Oct 2024 16:05:53 +0000 (+0200) Subject: wait #7116 @0:10 nettoyage X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=df6f33ed9faa0ba958ac24659f2022d1d6f56aeb;p=pmi.git wait #7116 @0:10 nettoyage --- diff --git a/app/SubForms/News.php b/app/SubForms/News.php index 137ea0a..d15498f 100644 --- a/app/SubForms/News.php +++ b/app/SubForms/News.php @@ -46,7 +46,7 @@ class News extends SubForm $this->addField(['name' => 'page_product', 'label' => 'Page produit', 'type' => 'SelectFromArray', - 'options' => self::products(request()->query('locale') ?? $this->defaultLang), + 'options' => self::getDataByModel('catalog_products'), 'multiple' => false, 'default' => '' ]); @@ -54,27 +54,24 @@ class News extends SubForm $this->addField(['name' => 'page_page', 'label' => 'Page generale', 'type' => 'SelectFromArray', - 'options' => self::pages(request()->query('locale') ?? $this->defaultLang), + 'options' => self::getDataByModel('cubist_cms_pages'), 'multiple' => false, ]); $this->addField(['name' => 'page_news', 'label' => 'Page actualités', 'type' => 'SelectFromArray', - 'options' => self::news(request()->query('locale') ?? $this->defaultLang), + 'options' => self::getDataByModel('cubist_news'), 'multiple' => false, ]); } - public function news($local) { - return DB::table('cubist_news')->whereNotNull("title->$local")->pluck("title->$local AS title",'id'); - } + public function getDataByModel($table) { + $column = 'title'; + $local = request()->query('locale') ?? $this->defaultLang; - public function products($local) { - return DB::table('catalog_products')->whereNotNull("name->$local")->pluck("name->$local AS name",'id'); - } + if($table === 'catalog_products') $column = 'name'; - public function pages($local) { - return DB::table('cubist_cms_pages')->whereNotNull("title->$local")->pluck("title->$local AS title",'id'); + return DB::table($table)->whereNotNull("$column->$local")->pluck("$column->$local AS $column",'id'); } }