Completed
Push — master ( 6bda75...c9c221 )
by Davide
02:32
created

Category::getCategoriesArray()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 0
dl 0
loc 10
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace DavideCasiraghi\LaravelSmartBlog\Models;
4
5
use Illuminate\Database\Eloquent\Model;
6
7
class Category extends Model
8
{
9
    /***************************************************************************/
10
    /**
11
     * The table associated with the model.
12
     *
13
     * @var string
14
     */
15
    protected $table = 'categories';
16
17
    /***************************************************************************/
18
19
    use \Dimsav\Translatable\Translatable;
0 ignored issues
show
introduced by
The trait Dimsav\Translatable\Translatable requires some properties which are not provided by DavideCasiraghi\LaravelSmartBlog\Models\Category: $translations, $translationModel, $localeKey, $translationForeignKey
Loading history...
20
21
    public $translatedAttributes = ['name', 'description', 'slug'];
22
    protected $fillable = [];
23
    public $useTranslationFallback = true;
24
25
    /***************************************************************************/
26
27
    /**
28
     * Return the post categories array
29
     * the collection is transferred to an array to symulate the pluck behaviour,
30
     * and get the category name translated or the relative fallbacks.
31
     * (otherwise the pluck has empty names because doesn't fallback).
32
     *
33
     * @return array
34
     */
35
    public static function getCategoriesArray()
36
    {
37
        $ret = [];
38
        $categories = self::get();
39
40
        foreach ($categories as $key => $category) {
41
            $ret[$category->id] = $category->name;
42
        }
43
44
        return $ret;
45
    }
46
    
47
    /***************************************************************************/
48
49
    /*
50
     * Return the category name.
51
     *
52
     * @param  int  $categoryId
53
     * @return string
54
     */
55
    /*public static function getCategoryName($categoryId)
56
    {
57
        $ret = self::find($categoryId)->name;
58
59
        return $ret;
60
    }*/
61
}
62